I am working on a project on which I have to preselect a particular cell.
I can preselect a cell using -willDisplayCell
, but I can't deselect it when the user clicks on any other cell.
- (void)tableView:(UITableView*)tableView
willDisplayCell:(UITableViewCell*)cell
forRowAtIndexPath:(NSIndexPath*)indexPath
{
AppDelegate_iPad *appDelegte =
(AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
if ([appDelegte.indexPathDelegate row] == [indexPath row])
{
[cell setSelected:YES];
}
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AppDelegate_iPad *appDelegte =
(AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
NSIndexPath *indexpath1 = appDelegte.indexPathDelegate;
appDelegte.indexPathDelegate = indexPath;
[materialTable deselectRowAtIndexPath:indexpath1 animated:NO];
}
Can you help?
Please check with the delegate method whether it is correct or not. For example;
for
Swift 2.0:
use this code
Swift 3.0:
Swift 4:
try this
Swift 3.0:
Following the protocol conformance section of the ray wenderlich swift style guide, to keep related methods grouped together, put this extension below your view controller class like that: