通常我的典型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
}
都不是以往任何时候都调用。
我放弃了。
现在不行biggy但这个困扰我没有尽头
这是一个完整didSelectRowForIndexPath这样你就可以验证有没有desellect命令有
-(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
}
我使用tableview与UIViewController不是UITableViewController。 –
+1。看起来我已经知道发生了什么事情。 –