0

通常、私の典型的な 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 の場合は、新しいウィンドウか何かを開きます。次に、行の選択をすばやく解除します。行の選択を解除しないということは、以前に選択した行がまだそこにあることを意味します。

ただし、過去のコードを確認すると、deselect をまったく呼び出さなかったにもかかわらず、行が正常に選択解除されていることがわかりました

行がいつどこで選択解除されたかを追跡するために、どこにでもトラップを配置します。

-(void)viewDidAppear:(BOOL)animated
{

...

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

}

たとえば、詳細から戻った後、self.tablevView.indexPathForSelectedRow は既に null です。行はすでに選択解除されていますが、いつ、どこで?

明らかな場所にトラップを追加します

-(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
}
4

2 に答える 2

3

これが のデフォルトの動作です。次UITableViewControllerのドキュメントを参照してくださいclearsSelectionOnViewWillAppear

このプロパティのデフォルト値は ですYES。の場合YES、Table View Controller はメッセージを受信すると、テーブルの現在の選択をクリアし viewWillAppear:ます。このプロパティを設定するとNO、選択が保持されます。

于 2013-01-09T09:27:49.407 に答える
0

更新:viewWillAppear行ごとはまだ選択されています。によってviewDidAppear、それはもうありません。それらの間にあります[table reload][table reload]行の選択を解除するように見えます。

于 2013-01-09T09:29:33.610 に答える