iOS7 Tableview删除行最佳实践 [英] iOS7 Tableview Delete Row Best Practice

查看:157
本文介绍了iOS7 Tableview删除行最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

On the iPhone there is a text book example of how to delete a tableview row in the Message Apps. This appears to use three separate views to perform the task.

我的问题是关于是否有快捷方式来实现这一目标,还是只创建三个屏幕并且做出明显的流血。

My question is about whether there are short cuts to achieve this or do you just create three screens and to do the bleedin' obvious.

非常感谢。

推荐答案

从故事板中删除行非常简单。您只需在TableView数据源中继承2个方法。首先是告诉行是否可以删除:

Removing a row from storyboard is pretty straightforward. You just have to inherit 2 methods in your TableView Data source. First is telling if a row can be deleted:

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

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

Second is removing the row from table view:

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

这篇关于iOS7 Tableview删除行最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆