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?
use this code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Change the selected background view of the cell.
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//Change the selected background view of the cell.
tableView.deselectRow(at: indexPath, animated: true)
}