我的segue中有这样的代码,来自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;
}
当我执行 segue 并返回时,我发现单元格仍在检查中。奇怪的是,scrollRectToVisible
同时滚动回顶部。
self.lastIndexPath
在每次选择时都会更新:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
self.lastIndexPath = indexPath;
self.nextButton.enabled = YES;
[tableView reloadData];
}
我检查cellForRowAtIndexPath
中的列表元素:
if ([indexPath compare:self.lastIndexPath] == NSOrderedSame)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
最佳答案
因此,您将最后一个选定单元格的 accessoryType
设置为 none,然后调用 reloadData
,但在 cellForRowAtIndexPath
中: lastIndexPath
仍然相同,您正在设置复选标记。
在调用 reloadData
之前尝试将 lastIndexPath
设置为 nil。
关于ios - 无法在 segue 中取消选中 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24577672/