为什么UIButton目标仅在以某种方式声明选择器时才起作用

时间:2017-02-07 07:30:35

标签: ios swift uibutton uibarbuttonitem

我真的很困惑为什么只有当我在视图中创建UIButton时才能使用,我希望得到一个答案,因为我试图清理我的viewDidLoad函数。

let logoutButton: UIBarButtonItem = {
    let button = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(handleLogout))
    return button
}()

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.leftBarButtonItem = logoutButton // Does not work
    // navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(handleLogout))
}

0 个答案:

没有答案