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 creation of the UIButton. How would I add in the timer to be sent down to the method? I've tried withObject:timer
but it gives me a warning and crashes at runtime.
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:(0.009) target:self selector:@selector(moveStickFig:) userInfo:stickFig repeats:YES];
[stickFig addTarget:self action:@selector(tapFig:andTime:) forControlEvents:UIControlEventTouchUpInside];
This is the method I'm sending it down to:
-(void) tapFig:(id)sender andTime:(NSTimer *)timer
I've also tried [stickFig performSelector:@selector(tapFig:andTime) withObject:nil withObject:timer]
after I defined the UIButton, but that also results in a warning and crashes.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With