iphone - 可编辑的 UITableView

标签 iphone ios uitableview uinavigationbar

我正在尝试设置一个我可以编辑的 UITableView。我实现了以下方法:

 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {

但我不确定如何将编辑链接到我的 UINavigationBar 中的编辑按钮。这是我的按钮项目:

UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit"
                                                                style:UIBarButtonSystemItemEdit 
                                                               target:nil 
                                                               action:@selector(editButtonSelected:)];

我如何让它工作?

最佳答案

我仅使用标准编辑按钮就取得了很多成功:

self.navigationItem.leftBarButtonItem = self.editButtonItem;

您的代码的问题是您没有设置目标。如果 editButtonSelected: 选择器在您设置它的 View Controller 中,请像这样使用“self”:

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)];

关于iphone - 可编辑的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4905173/

相关文章:

ios - Spritekit 添加音效

iphone - 从单个方法实例化一定数量的唯一对象

Swift - 内容 View 的大小与 UITableViewCell 不匹配

iPhone ScrollView 和 Picker 问题

iphone - 图片加载

ios - 快速过滤和排序字典数组

c# - 如何将自定义 `UITableCell` 提供给 `UITableView`,使其具有与内置单元格相同的布局指标?

ios - 获取 UITableView 中 Core Data 对象的 indexPath

iphone - 在 Objective-C 中执行一系列 SOAP 请求的更好方法

iPhone 模拟器卡住整个操作系统