I'm trying to figure out how events work. In Stanford's 4 year video on iTunes U, Alan Cannistroro says there is
"3 different tastes of the type of choice of the method of action - (void) actionMethod; - (void) actionMethod: (id) sender; - (void) actionMethod: (id) sender withEvent: (UIEvent *) event;"
I thought I would try them with a simple add program - you enter 2 numbers, and as you enter the amount, it gets places in the 3rd UITextField. I have a method with a signature without parameters, and it works fine. When I change it to the second one with the sender parameter, the code stops calling the method.
It works:
-(void) setSum { float a1 = addend1.text.floatValue; float a2 = addend2.text.floatValue; float thesum = a1 + a2; NSString * ssum = [NSString stringWithFormat:@"%g", thesum]; sum.text = ssum; } -(void)awakeFromNib { SEL setSumMethod = @selector(setSum); [addend1 addTarget: self action: setSumMethod forControlEvents: UIControlEventEditingChanged]; [addend2 addTarget: self action: setSumMethod forControlEvents: UIControlEventEditingChanged]; }
This executes, but setSum is not called:
-(void) setSum:(id) sender { float a1 = addend1.text.floatValue; float a2 = addend2.text.floatValue; float thesum = a1 + a2; NSString * ssum = [NSString stringWithFormat:@"%g", thesum]; sum.text = ssum; } -(void)awakeFromNib { SEL setSumMethod = @selector(setSum:); [addend1 addTarget: self action: setSumMethod forControlEvents: UIControlEventEditingChanged]; [addend2 addTarget: self action: setSumMethod forControlEvents: UIControlEventEditingChanged]; }
So, the question is, when do other types of event methods work? Only the first seems to apply.
TIA
Mark
source share