swift - 在 rightBarButtonItem 中访问 UIButton

标签 swift

我有一个带有正确 UIBarButtonItem 的导航 Controller 。我已将 UIButton 添加到 BarButtonItem。

如果可能的话,我如何在运行时到达按钮而不使用标签?

最佳答案

var myButton:UIButton?

var rightButton = navigationItem.rightBarButtonItems?.first
for view in rightButton.subviews() {
    if view.iskindOfClass(UIButton) {
        myButton = view
        break
    }
}

关于swift - 在 rightBarButtonItem 中访问 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224245/

相关文章:

swift - 使用 MBProgressView 取消按钮

ios - 何时在 Swift 中使用全局变量

uitableview - UITableViewCell 和 UIViewController 之间通信的最佳方式

ios - 禁用与 segue 的文本字段交互

ios - 如何在自定义 UIView 的单独文件中向 UIViewController 发送消息

ios - 为什么列表在 Swift 的另一个函数中使用时会变空?

ios - 如何在 iOS App Swift 4 中集成 Paypal 支付方式?

swift - 弹出窗口中没有摘要信息 -- Option-Click

swift - 重置 UIStepper 的值

ios - 使用 SwiftyDropbox 创建指向文件的共享链接