0

セルが選択されたときにビューコントローラーをプッシュする単純なグループ化されたテーブルビューがあります。ナビゲーション バーの左の項目は、テーブル ビューを「編集モード」にします。編集モードでは、必要に応じて各セルを移動および削除できます。私が望むのは、編集モードのときと通常モードのときに別のビューコントローラーをプッシュできるようにすることです。

これは、View Controller がプッシュされている場所です。

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...stuff that doesnt matter...

[[self navigationController] pushViewController:detailViewController animated:YES];


}

BarButtonItems はここで宣言されています。

    [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];

これは、すべての編集内容が宣言されている場所です。

- (void)tableView:(UITableView *)atableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

if (editingStyle == UITableViewCellEditingStyleDelete)
{
    [atableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
}
}

- (void)tableView:(UITableView *)atableView 
moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath 
  toIndexPath:(NSIndexPath *)destinationIndexPath
{
[[BNRItemStore sharedStore] moveItemAtIndex:[sourceIndexPath row] 
                                    toIndex:[destinationIndexPath row]];
}
4

1 に答える 1

2

ビューコントローラーを didSelectRowAtIndexPath にプッシュすると、テーブルビューが編集モードかどうかを確認できます。そうであれば、別のView Controllerをプッシュできます。

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      ...stuff that doesnt matter...
         if(aTableView.editing) // The tableview is in editing mode
      [[self navigationController] pushViewController:otherViewController animated:YES];
      else [[self navigationController] pushViewController:detailViewController animated:YES];


}

編集は、テーブルビューが現在編集モードの場合に YES を返すプロパティです。

于 2012-07-11T02:08:57.123 に答える