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