0

I have a simple grouped table view that when a cell is selected it pushes a 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 中推送视图控制器时,您可以检查 tableview 是否处于编辑模式。如果是,您可以推送不同的视图控制器。

- (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];


}

如果 tableview 当前处于编辑模式,则 editing 是一个返回 YES 的属性。

于 2012-07-11T02:08:57.123 回答