Objective C: Sending arguments to a method called by a UIButton

后端 未结 6 753
甜味超标
甜味超标 2021-01-06 10:26

I have a method that is being called when a UIButton is clicked. When I create the button I want it to store an NSTimer as an argument.

This is the timer and the cr

6条回答
  •  情歌与酒
    2021-01-06 11:12

    You can't - UIControl action selectors are invoked with no parameters, the control that is the source of the action, or the control that is the source of the action and the UIEvent which occurred on that control. In IB you have to connect the UIButton to such a method: you can't add any other custom parameters.

    If you want it to have access to other objects, they need to be instance variables.

    Review Apple's Introduction to Objective C if you want to understand how to define instance variables.

提交回复
热议问题