【问题标题】:How to invoke built-in "Edit" and "Add" functionality in UIToolbar custom buttons如何在 UIToolbar 自定义按钮中调用内置的“编辑”和“添加”功能
【发布时间】:2011-11-03 20:05:30
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: iphone ios4 uitoolbar


    【解决方案1】:
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(callEdit)];
    

    在 callEdit 方法中。

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

    【讨论】:

    • 非常感谢@iPhoneiPadDev 的回答。但如果我这样做,它不会在导航栏上设置按钮,而不是在工具栏上?另外,我希望工具栏上的按钮放置在左右角,我无法通过编程实现,因此我使用了 IB(灵活空格键按钮项)。如何在 IB 中创建的按钮上使用以下语句 - 'code' [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(callEdit)]; '代码'。 “alloc” stmt 不会给我错误,因为它已经在 IB 中创建了吗?
    • 有人可以帮我吗?
    • 嗨@iPhoneiPadDev 我能够显示编辑和添加按钮。但是我如何实现上面提到的“callEdit”方法。我无法弄清楚您上面的答案中的“tblView”是什么。我有一个基于导航的应用程序,我的 tableviewcontroller 称为 RootViewController。我应该为我的 RootViewController 创建一个 IBOutlet 吗?请告诉我
    猜你喜欢
    • 2021-05-21
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多