0

Background - I'm trying to make my controller deselect a row when its selected and tapped

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if ([cell isSelected]) {
        // Deselect manually.
        [tableView.delegate tableView:tableView willDeselectRowAtIndexPath:indexPath];
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
        [tableView.delegate tableView:tableView didDeselectRowAtIndexPath:indexPath];
        self.selectedRow = -1;

        [tableView beginUpdates];
        [tableView setTableHeaderView:self.headerView];
        [tableView endUpdates];
    } else {

        self.selectedRow = indexPath.row;
        [tableView beginUpdates];
        [tableView setTableHeaderView:nil];
        [tableView endUpdates];

    }

    return indexPath;
}

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
   return [super tableView:tableView willDeselectRowAtIndexPath:indexPath];
}

When the code executes and a row is tapped while selected:

tableView:willDeselectRowAtIndexPath:]: unrecognized selector sent to instance 0xbf59e00

My Controller inherits from UITableViewController. Its set as the delegate on the tableView. What am I missing?

fansonly
  • 1,150
  • 4
  • 14
  • 29
  • aznatam has the correct answer below. The event above, willDeselectRowAtIndexPath, is called when the row is about to be deselected. This does NOT deselect it. Since your controller inherits from UITableViewController, you also don't need to call super for your table methods. You use super to call the code in the inheriting class and then your code when you are overriding the method. A delegate method has no implementation from its parent aka super class. – Justin Holman Aug 21 '14 at 17:23
  • yeah, makes sense. but why am I getting the error: tableView:willDeselectRowAtIndexPath:]: unrecognized selector sent to instance 0xbf59e00 – fansonly Aug 21 '14 at 18:06

1 Answers1

1

You can check this link

How to deselect a selected UITableView cell?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
//Change the selected background view of the cell.
 [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Community
  • 1
  • 1
aznatam
  • 204
  • 1
  • 4