如何在UIToolbar自定义按钮中调用内置的“编辑”和“添加”功能

时间:2011-09-13 03:23:13

标签: iphone ios4 uitoolbar

我在uinavigationcontroller中使用IB添加了uitoolbar(通过选中复选框 - “显示工具栏”)。我使用IB,因为这很容易添加灵活的间距栏按钮(我不想以编程方式处理间距代码)。 我的问题是我想调用我添加的2个工具栏按钮的内置编辑和添加功能。我知道在导航栏中我可以使用以下代码,它将调用此功能

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];

上面的代码负责“编辑视图”,其中表格视图项目旁边有一个删除按钮。

如何为添加到工具栏的按钮实现相同的功能?我正在使用Xcode 4.请指出一些代码示例。

1 个答案:

答案 0 :(得分:1)

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(callEdit)];

在callEdit方法中。

-(void)callEdit {
     [self.tableView setEditing:YES];
}