Cannot execute method when passed as a parameter iPhone/iPad
I am trying to learn how to pass methods as parameters and then later execute them. In my code I have a method that get's called when clicking a button (last method) I am trying to pass method1 and method2开发者_开发技巧 to the method placeSlide. I am able to do that but when I try to execute them I get an error. What am I doing wrong?
-(void) method1{
}
-(void) method2{
}
-(void) placeSlide: (SEL) meth1 OtherMethod: (SEL) meth2{
NSTimer *timer1;
timer1 = [NSTimer scheduledTimerWithTimeInterval: (1)
target: self
selector: @selector(meth1)
userInfo: nil
repeats: NO];
NSTimer *timer2;
timer2 = [NSTimer scheduledTimerWithTimeInterval: (1.2)
target: self
selector: @selector(meth2)
userInfo: nil
repeats: NO];
}
// get's executed when I click on a btn
-(IBAction) ButtonClick{
[self placeSlide:@selector(method1) OtherMethod:@selector(method2)];
}
and the error that I am getting is:
Just pass the SEL
variables as they are.
NSTimer *timer1;
timer1 = [NSTimer scheduledTimerWithTimeInterval: (1)
target: self
selector: meth1
userInfo: nil
repeats: NO];
NSTimer *timer2;
timer2 = [NSTimer scheduledTimerWithTimeInterval: (1.2)
target: self
selector: meth2
userInfo: nil
repeats: NO];
精彩评论