can I pass a method as an argument?
I don’t succeed to pass the method targetOpenView in the example below:
-(void) targetTimeView:(id)sender {
[self TimeViewWithtimeInterval:.6 selector:targetOpenView]; //targetOpenView does NOT work
}
-(void) timeViewWithtimeInterval:(float)interval selector:openViewMethod{
[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(openViewMethod) userInfo:nil repeats:NO];
}
Any suggestions how I could make this work? Thanks!
You need the
@selectorcompiler directive to extract the select from a method name, like you did when creating the timer:And define your argument to the type
SEL:Then, when passing the argument to the NSTimer method you can leave off the
@selectorsince the type is already a selector: