iOS11 UIBarButtonItem action not get called

前端 未结 6 1314
花落未央
花落未央 2021-01-12 11:06

I used Xcode9 Beta6 to build the project, the action was called correctly on iOS10 device, however it is not work on iOS11 device.

In My project, there are some view

6条回答
  •  醉酒成梦
    2021-01-12 11:17

    In my case I was setting up the button and instantiating it as a property of the vc

    class myVC: UIViewController {
    let closeBarButtonItem = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(close(_:)))
    }
    

    If I moved this to ViewDidLoad it resolved the problem

    class myVC: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let closeBarButtonItem = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(close(_:)))
    }
    

    }

提交回复
热议问题