TableView正在编辑时调用不同的ViewController

时间:2012-07-11 01:58:05

标签: objective-c ios xcode cocoa-touch editing

我有一个简单的分组表视图,当选择一个单元格时,它会推送一个View控制器。导航栏的左侧项目将表格视图置于“编辑模式”。在编辑模式下,您可以根据需要移动和删除每个单元格。我想要的是能够在编辑模式下推动单独的视图控制器,然后在正常模式下。

这是推送视图控制器的地方:

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

1 个答案:

答案 0 :(得分: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当前处于编辑模式,则返回YES。

相关问题