在iPhone上有一个教科书示例,说明如何删除消息应用程序中的tableview行.这似乎使用三个单独的视图来执行任务.
我的问题是关于是否有实现这一目标的捷径,或者你是否只创建了三个屏幕并且显而易见.
非常感谢.
您必须实现必要的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]; } }
从故事板中删除行非常简单.您只需在TableView数据源中继承2个方法.首先是告诉是否可以删除行:
- (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]; }