0

tableViewで選択された行に問題があります。選択した行を選択すると、前のナビゲーションコントローラーに戻ると、行の選択が解除されました。iPhoneは選択された行を記憶できますか?コントローラーを押すと、選択された行が記憶され、青色になりますか?

4

2 に答える 2

1

オブジェクトが通常物事を「記憶」する方法は、オブジェクトをインスタンス変数に格納することです。したがって、選択した行を追跡する簡単な方法は、インスタンス変数と型のプロパティをNSIndexPath *リスト コントローラーに追加することです。次に、プロパティを使用して、テーブル ビュー コントローラーのメソッドに渡された indexPath を格納できます-tableView:didSelectRowAtIndexPath:

次に、次のように、リスト コントローラーで継承された -viewWillAppear: メソッドをオーバーライドして、テーブル ビューにメッセージを送信し、行を再選択することができます。

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // Good idea to reload the table view's cells
    // in case the underlying data was changed by
    // another view controller.
    [[self tableView] reloadData];

    // Assuming you added a selectedIndexPath property
    // to your list controller...
    //
    if ([self selectedIndexPath] != nil)
    {
        // Select the row. Note that you need to be sure
        // that the table view is scrolled so that the
        // selected row is visible.
        [[self tableView] selectRowAtIndexPath:[self selectedIndexPath]
                                      animated:NO
                                scrollPosition:UITableViewScrollPositionMiddle];
        // Get rid of the saved selection
        [self setSelectedIndexPath:nil];
    }
}
于 2010-03-09T17:30:16.160 に答える
0

選択した行のインデックスをファイル (info.plist? properties.plist) に保存して、iPhone の状態を維持することをお勧めします。次に、そのビューに戻ったら、選択した行をファイルから取得し、選択した行のインデックスを変更します。

于 2010-03-09T14:11:46.077 に答える