iOS7 Tableview删除行最佳实践

在这里输入图像说明

在iPhone上,有一个关于如何在消息应用程序中删除一个tableview行的文本示例。 这似乎使用三个单独的视图来执行任务。

我的问题是关于是否有捷径来实现这一目标,或者您是否创build了三个屏幕,并做出了明显的stream血。

非常感谢。

从故事板中删除一行非常简单。 你只需要在你的TableView数据源中inheritance2个方法。 首先是告诉你是否可以删除一行:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } 

其次是从表视图中删除行:

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } 

你必须实现必要的UITableViewDelegate和UITableViewDataSource方法。

首先,添加这个:

 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [self.dataArray removeObjectAtIndex:indexPath.row]; [tableView reloadData]; } } 

我不是很确定你的意思有三个不同的意见,但是这将是一个从UITableView删除行的例子的解决scheme:

http://www.appcoda.com/model-view-controller-delete-table-row-from-uitableview/

下面的步骤,你应该按照从tableView删除任何行:

  1. 获取要删除的行的indexPath

  2. 从tableView数据源的数据模型中删除行。

[yourDataModel removeObjectAtIndex:indexPath.row];

  1. 通过重新加载tableView来更新屏幕。

[tableView reloadData];

让我知道是否需要更多的信息。