【问题标题】:iOS >> UIBarButton >> Set Identifier from CodeiOS >> UIBarButton >> 从代码中设置标识符
【发布时间】:2014-01-13 12:16:43
【问题描述】:

我在导航栏中有一个 UIBarButton(VC 嵌入在导航控制器中)。 在 IB 中,我使用标识符设置按钮:

如何从代码中设置此属性?

【问题讨论】:

    标签: ios properties uibarbuttonitem identifier


    【解决方案1】:

    你应该可以这样设置

    UIBarButtonItem *trashButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:nil];
    

    查看此here 的 Apple 文档

    不幸的是,Apple 只允许您在初始化 UIBarButtonItem 时设置它,没有属性可以设置它。

    【讨论】:

    • 所以这意味着我每次都必须创建一个新按钮?我阅读了文档,似乎很奇怪没有 Property 或 setIdentifier:ForState 方法...
    • 是的,不幸的是没有属性可以设置,当你alloc init时你必须这样做。烦人,但这正是 Apple 喜欢的方式——烦人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 2013-09-19
    相关资源
    最近更新 更多