Pass multiple parameters to addTarget

前端 未结 5 1944
小鲜肉
小鲜肉 2020-12-05 08:46

In my UITableViewCell I have a button. And I want to add action to it by passing multiple parameters in cellForRowAtIndexPath method.



        
5条回答
  •  既然无缘
    2020-12-05 09:01

    If you need to pass string just use accessibilityHint of UIButton.

    Tag can only store Int so if anyone wants to pass string data can use this. However, this not a proper way of passing data!

    example:

    button.accessibilityHint = "your string data"
    button.addTarget(self, action: Selector(("buttonTapped")), for: UIControlEvents.touchUpInside)
    
    func buttonTapped (sender: UIButton) {
       let section = sender.accessibilityHint
    }
    

提交回复
热议问题