簡體   English   中英

無法在Segue中取消選中UITableViewCell

[英]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 ,但是在cellForRowAtIndexPathlastIndexPath仍然相同,並且要設置選中標記。 嘗試在調用reloadData之前將lastIndexPath設置為nil。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM