Reputation: 75
i want to send parameter to my details func with selector but it does not work, how can i do this?
btnDetails.addTarget(self, action:#selector(goToDetailsFromMap(mid:id)), for: .touchUpInside)
Upvotes: 0
Views: 524
Reputation: 3402
You can create a custom button:
class CustomButton: UIButton {
var someId: Int?
...
}
Then in your viewController
...
btnDetails.someId = ...
btnDetails.addTarget(self, action:#selector(didTapCustomButton(_:)), for: .touchUpInside)
...
@objc func didTapCustomButton(_ sender: CustomButton) {
if let id = sender.someId {
//Do something with id
}
}
Upvotes: 1
Reputation: 53
adding selector to button with code using swift 5.0
myButton.addTarget(self, action:#selector(myButtonTapped), for: .touchUpInside)
function declaration
@objc func myButtonTapped() {
//do stuff here
}
Upvotes: 0