【问题标题】:Cell get unselected without deselect command单元格在没有取消选择命令的情况下被取消选择
【发布时间】:2012-12-23 07:07:05
【问题描述】:

通常我典型的 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];
}

所以如果一行是selectec,打开一个新窗口或其他东西。然后快速取消选择该行。不取消选择行意味着当我们取回之前选择的行时,之前选择的行仍然存在。

但是,如果我查看我过去的代码,我发现该行已成功取消选择,即使我根本没有调用取消选择

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

-(void)viewDidAppear:(BOOL)animated
{

...

PO(self.tableView.indexPathForSelectedRow); //always show null here
while(false);

}

viewDidAppear 显示,在我从详细信息返回后,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
}

【问题讨论】:

    标签: php objective-c noop


    【解决方案1】:

    这是UITableViewController的默认行为,见clearsSelectionOnViewWillAppear的文档:

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

    【讨论】:

    • 我正在使用带有 UIViewController 而不是 UITableViewController 的 tableView。
    【解决方案2】:

    更新:viewWillAppear 行仍然被选中。 viewDidAppear,它不再是。他们之间有[table reload]。看起来像 [table reload] 取消选择该行。

    【讨论】:

      猜你喜欢
      • 2021-08-28
      • 2015-03-16
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多