I am trying to force selection(highlight) of a UITableViewCell using selectRowAtIndexPath..
For eg, Lets say i want to always have the first cell in a table view to be highlighted,I apply the following logic in viewDidAppear
[self.tableViewPrompts selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
Works nicely.But when i try to apply the same logic elsewhere in the application the cell is not selected.I even tried deselecting other cells before calling the above method and reloading tableview before and after calling this method but none of the approaches seem to work!
I even used the tableview's delegate to forcibly make a call to the didSelectRowAtIndexPath.Event this does not work.
PS: The selection of the cell does not trigger any action all i am trying to achieve is highlighting the desired cell.
What am i doing wrong here?
Help is greatly appreciated!!
The selection of the cell does not trigger any action all i am trying to achieve is highlighting the desired cell.
Why don't you use the cell's highlighted property?
UITableViewCell *cell = [self cellForRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: 0]];
cell.highlighted = YES;
Cant test it now, but it should work.....
edit
Better yet, of course: change your cellForRowAtIndexPath to do that
-(UITableViewCell) tableView:cellForRowAtIndexPath:
//...
if (indexPath.row == 0 && indexPath.section == 0) cell.highlighted = YES
else cell.highlighted = NO;
//...
return cell;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With