iOS11 UIBarButtonItem action not get called

前端 未结 6 1303
花落未央
花落未央 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:29

    It is happening only for iOS 11 and when custom UIView used for rightBarButtonItem (or left also). If you are using UIBarButtonItem then it will work fine. There is 0 width of this custom bar item, so we need to set it to something.

    In viewDidLoad of this controller you can add code, you can replace 100 to something what will work for you:

    if let view = self.navigationItem.rightBarButtonItem?.customView {
        view.widthAnchor.constraint(equalToConstant: 100).isActive = true
    }
    

    At least as an easy temporary solution it is fine.

提交回复
热议问题