当TableView正在编辑时调用不同的ViewController
问题描述:
我有一个简单的分组表格视图,当选中一个单元格时,它将推送一个View控制器。导航栏的左侧项目将表格视图置于“编辑模式”。在编辑模式下,您可以根据需要移动和删除每个单元格。我想要的是,当它处于编辑模式时,能够推送独立的视图控制器,然后处于正常模式。当TableView正在编辑时调用不同的ViewController
这就是视图控制器推:
- (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]];
}
答
在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。
感谢您的帮助,但它似乎并没有工作。我无法选择表格单元,而它的编辑模式,我havnt制作了视图控制器,但我做了如果(atableView.editing){NSLog(@“编辑”)}并没有得到任何反馈... – user1438042 2012-07-11 15:41:52