UITableview: How to Disable Selection for Some Rows but Not Others

You just have to put this code into cellForRowAtIndexPath To disable the cell’s selection property: (while tapping the cell) cell.selectionStyle = UITableViewCellSelectionStyleNone; To enable being able to select (tap) the cell: (tapping the cell) // Default style cell.selectionStyle = UITableViewCellSelectionStyleBlue; // Gray style cell.selectionStyle = UITableViewCellSelectionStyleGray; Note that a cell with selectionStyle = UITableViewCellSelectionStyleNone; will … Read more

Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:

You’re using the dequeueReusableCellWithIdentifier:forIndexPath: method. The documentation for that method says this: Important: You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method. You didn’t register a nib or a class for the reuse identifier “Cell”. Looking at your code, you seem to expect the dequeue method … Read more

UITableView Cell selected Color?

No need for custom cells. If you only want to change the selected color of the cell, you can do this: Objective-C: UIView *bgColorView = [[UIView alloc] init]; bgColorView.backgroundColor = [UIColor redColor]; [cell setSelectedBackgroundView:bgColorView]; Swift: let bgColorView = UIView() bgColorView.backgroundColor = UIColor.red cell.selectedBackgroundView = bgColorView

UITableView – change section header color

This is an old question, but I think the answer needs to be updated. This method does not involve defining and creating your own custom view. In iOS 6 and up, you can easily change the background color and the text color by defining the -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section section delegate method For example: … Read more

How to pass prepareForSegue: an object

Simply grab a reference to the target view controller in prepareForSegue: method and pass any objects you need to there. Here’s an example… – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Make sure your segue name in storyboard is the same as this line if ([[segue identifier] isEqualToString:@”YOUR_SEGUE_NAME_HERE”]) { // Get reference to the destination view controller … Read more

How to remove empty cells in UITableView? [duplicate]

Set a zero height table footer view (perhaps in your viewDidLoad method), like so: Swift: tableView.tableFooterView = UIView() Objective-C: tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; Because the table thinks there is a footer to show, it doesn’t display any cells beyond those you explicitly asked for. Interface builder pro-tip: If you are using a xib/Storyboard, you … Read more

Can you animate a height change on a UITableViewCell when selected?

I found a REALLY SIMPLE solution to this as a side-effect to a UITableView I was working on….. Store the cell height in a variable that reports the original height normally via the tableView: heightForRowAtIndexPath:, then when you want to animate a height change, simply change the value of the variable and call this… [tableView … Read more

UITableView – scroll to the top

UITableView is a subclass of UIScrollView, so you can also use: [mainTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]; Or [mainTableView setContentOffset:CGPointZero animated:YES]; And in Swift: mainTableView.setContentOffset(CGPointZero, animated:true) And in Swift 3 & above: mainTableView.setContentOffset(.zero, animated: true)

UITableViewCell, show delete button on swipe

During startup in (-viewDidLoad or in storyboard) do: self.tableView.allowsMultipleSelectionDuringEditing = false Override to support conditional editing of the table view. This only needs to be implemented if you are going to be returning NO for some items. By default, all items are editable. – (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return YES if you want … Read more

tech