我从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;
}
当我执行搜索并返回时,我看到该单元仍处于检查状态。奇怪的是,
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
设置为无,然后调用reloadData
,但是在cellForRowAtIndexPath
中:lastIndexPath
仍然相同,并且要设置选中标记。
尝试在调用lastIndexPath
之前将其设置为nil reloadData
。
关于ios - 无法取消选中SeTable中的UITableViewCell,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24577672/