当作为参数iPhone/iPad传递时,无法执行方法
我试图学习如何将方法作为参数传递,然后在以后执行它们。在我的代码中,我有一个方法,当我试图将method1和method2传递给方法placeSlide时,单击按钮(最后一个方法)会调用get。我可以这样做,但当我试图执行它们时,我会出错。我做错了什么当作为参数iPhone/iPad传递时,无法执行方法,iphone,objective-c,ipad,pointers,Iphone,Objective C,Ipad,Pointers,我试图学习如何将方法作为参数传递,然后在以后执行它们。在我的代码中,我有一个方法,当我试图将method1和method2传递给方法placeSlide时,单击按钮(最后一个方法)会调用get。我可以这样做,但当我试图执行它们时,我会出错。我做错了什么 -(void) method1{ } -(void) method2{ } -(void) placeSlide: (SEL) meth1 OtherMethod: (SEL) meth2{ NSTimer *timer1;
-(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)];
}
我得到的错误是:
只需按原样传递
SEL
变量即可
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];
只需按原样传递
SEL
变量即可
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];