在没有取消选择命令的情况下取消选择单元格


Cell get unselected without deselect command

通常我的典型didselectrowatindexpath是这样的:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    BGUIBusinessCellForDisplay * cellBiz = (BGUIBusinessCellForDisplay *) cell;
    [BGDetailBusinessViewController detailButtonPressed:cellBiz.biz withNavController:self.navigationController];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

因此,如果选择了一行,请打开一个新窗口或其他什么。然后快速取消选择该行。不取消选择行意味着当我们返回时,先前选择的行仍然存在。

然而,如果我检查我过去的代码,我看到行被成功地取消选择,即使我根本没有调用取消选择

我在各处设置了一个陷阱来跟踪取消选择行的位置和时间:

-(void)viewDidAppear:(BOOL)animated
{
...
PO(self.tableView.indexPathForSelectedRow); //always show null here
while(false);

}

事实证明,在我从细节返回后,self.tablevView.indexPathForSelectedRow已经为空。因此,该行已被取消选择,但何时何地?

我在明显的地方设置了更多的陷阱

-(void)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    while (false);//breakpoint here never called
}
-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *) indexPath
{
    while (false); //breakpoint here never called 
}

这些都没有被调用过。

我放弃了。

现在不是很大,但这让我困惑不已

这是完整的didSelectRowForIndexPath,因此您可以验证中是否没有取消收集的命令

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    if ([cell isKindOfClass:[BGUIBusinessCellForDisplay class]])
    {
        BGUIBusinessCellForDisplay * cellBiz = (BGUIBusinessCellForDisplay *) cell;
        [BGDetailBusinessViewController detailButtonPressed:cellBiz.biz withNavController:self.navigationController];
    }
    else if ([cell isKindOfClass:[BGAddMoreBusiness class]])
    {
        BGBusinessEditViewController * editBusiness = [[BGBusinessEditViewController alloc]init];
        [self.navigationController SafelyPushController:editBusiness];
    }
    PO(self.tableView.indexPathForSelectedRow); //not null here
}

这是UITableViewController的默认行为,请参阅clearsSelectionOnViewWillAppear:的文档

此属性的默认值为YES。当YES时,表视图控制器在接收到viewWillAppear:消息。将此属性设置为NO将保留选择

更新:按viewWillAppear行仍处于选中状态。到了viewDidAppear,它就不再是了。在它们之间有[table reload]。看起来[table reload]取消选择该行。