【问题标题】:Set UIBarButtonItem to a UIBarButtonSystemItem programmatically以编程方式将 UIBarButtonItem 设置为 UIBarButtonSystemItem
【发布时间】:2012-06-28 23:54:37
【问题描述】:

我可以将系统项分配给UIBarButtonItem 而无需重新创建它吗?仅在现有按钮上调用 initWithBarButtonSystemItem 似乎对我不起作用。

This 是我试图让它工作的代码。我正在尝试使用 PhoneGap 改进对 iOS 的本机控件支持。该插件可以毫无问题地更改标题/图像,但我必须弄清楚如何将系统提供的图标分配给现有按钮。

【问题讨论】:

    标签: ios uibarbuttonitem


    【解决方案1】:

    我查看了您的代码,没有发现您使用initWithBarButtonSystemItem。然而,这是我在原生 iOS 编程的类似案例中所做的:

    UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
    
    self.navigationItem.rightBarButtonItem = myButton;
    [myButton release];
    

    这对我来说是正确的。我不熟悉 PhoneGap,但它可能会也可能不会改变。

    【讨论】:

    • 很好,像这样分配一个新按钮可以按预期工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多