How to set the action for a UIBarButtonItem in Swift

前端 未结 5 2133
余生分开走
余生分开走 2020-12-12 19:51

How can the action for a custom UIBarButtonItem in Swift be set?

The following code successfully places the button in the navigation bar:

var b = UIB         


        
5条回答
  •  情话喂你
    2020-12-12 20:58

    Swift 5

    if you have created UIBarButtonItem in Interface Builder and you connected outlet to item and want to bind selector programmatically.

    Don't forget to set target and selector.

    addAppointmentButton.action = #selector(moveToAddAppointment)
    addAppointmentButton.target = self
    
    @objc private func moveToAddAppointment() {
         self.presenter.goToCreateNewAppointment()
    }
    

提交回复
热议问题