[英]Cannot uncheck UITableViewCell in 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;
}
當我執行搜索並返回時,我看到該單元仍在檢查中。 奇怪的是, scrollRectToVisible
會同時滾動回到頂部。
self.lastIndexPath
在每個選擇上都會更新:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
self.lastIndexPath = indexPath;
self.nextButton.enabled = YES;
[tableView reloadData];
}
我檢查cellForRowAtIndexPath
的list元素:
if ([indexPath compare:self.lastIndexPath] == NSOrderedSame)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
因此,您要為最后一個選定的單元格將accessoryType
設置為無,然后調用reloadData
,但是在cellForRowAtIndexPath
: lastIndexPath
仍然相同,並且要設置選中標記。 嘗試在調用reloadData
之前將lastIndexPath
設置為nil。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.