Do you have a socket for your button? Is the button the only user interface element that will send -startClick :? If so, write the action method as follows:
- (IBAction)startClick:(id)sender { NSParameterAssert(sender == self.startClickButton); if (sender == self.startClickButton) { UIButton *button = self.startClickButton; [...] } }
If you do not have an exit / property button for the button, you can test the sender class and, if necessary, perform the cast.
- (IBAction)startClick:(id)sender { NSParameterAssert([sender isKindOfClass: [UIButton class]]); if ([sender isKindOfClass: [UIButton class]]) { UIButton *button = (UIButton *)sender; [...] } }
Finally, it is permissible (at compile time) to send any message to the value entered by the identifier. (At run time, you will get an exception if the recipient does not respond to this message.) However, you cannot use the dot syntax.
So, if you know that the sender is always a button, you can write your method without castings. You will need to use message sending syntax instead of dot syntax.
[button setAnimationImages: [NSArray ...]]; [button setAnimationDuration: 1];
It is important to understand that the syntax of a point is equivalent to the syntax of sending a message - it is not mystical.
source share