Reputation: 1003
I have such code in my segue from a button in navigation bar of UITableViewController
:
if ([segue.identifier isEqualToString:@"groupInitialSelect"]) {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastIndexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
[self.tableView reloadData];
TTPDepartment *dep = [self.departmentList objectAtIndexedSubscript:self.lastIndexPath.row];
TTPGroupViewController *controller = [segue destinationViewController];
controller.selectedDepartment = dep;
}
When I perform a segue and come back I see that the cell is still checked. Strangely, scrollRectToVisible
is scrolling back to the top on the same time.
self.lastIndexPath
is updated on each selection:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
self.lastIndexPath = indexPath;
self.nextButton.enabled = YES;
[tableView reloadData];
}
I check the list element in cellForRowAtIndexPath
:
if ([indexPath compare:self.lastIndexPath] == NSOrderedSame)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
Upvotes: 0
Views: 36
Reputation: 7633
So you're setting the accessoryType
to none for the last selected cell and then You call reloadData
, but in the cellForRowAtIndexPath
: the lastIndexPath
is still the same and you're setting the checkmark.
Try to set to nil lastIndexPath
before the call to reloadData
.
Upvotes: 1