views:

67

answers:

3

How do you disable selecting only a single cell in a UITableView? I have several, and I only want the last to be disabled.

+1  A: 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = ...

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

}
camilin87
This will prevent the cell from appearing to be selected, but `tableView:didSelectRowAtIndexPath:` will still be called.
Brian
+2  A: 
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self numberOfRowsInSection] == [indexPath row]) {
        return nil;
    } else {
        return indexPath;
    }
}

the last row of the table will not be selected

Aaron Saunders
This will prevent the cell from actually being selected, but it will still be highlighted when the user touches it
Brian
Sorry, need to add UITableViewCellSelectionStyleNone style to the cell
Aaron Saunders
+1  A: 

Duplicate from http://stackoverflow.com/questions/2267993/uitableview-how-to-disable-selection-for-some-rows-but-not-others

Read all the answers, not just the "accepted" one.

Nir Levy