I am having problems with implementing delegates, and I'm sure I'm doing something silly. Would appreciate help from the experts here..... I can get a simple case to work, where I invoke a delegate method with no parameters passed, but I can't get the case where I invoke the delegate method and want to pass an additional object (or flag).
I've written small program to illustrate my problem. I have two classes, say Foo and Bar. The code allows a user to push a button on a screen, which starts a process in Foo (a controller type class). Foo starts a progress bar item on the screen, and calls a method in class Bar (model class). The method in Bar fires up a timer (NSTimer) and returns immediately. When the timer expires, I want to communicate to class Foo that the event was completed.
I am using a design pattern that was available online, and for the most part everything seems to be working. In the code below, I fail the condition where I check to see if "_delegate" responds to the selector (test:didFinish:).
- (void) doneWithTimer: (NSTimer *) aTimer {
NSLog(@"Bar: time over....");
if ([_delegate respondsToSelector:@selector(test:didFinish:) ]) { [_delegate test: self didFinish: true]; } else { [NSException raise:NSInternalInconsistencyException format:@"Foo doesn't respond to selector"]; }
}
If I have a simple method with no additional parameters, the code works fine. So, the following works....
- (void) doneWithTimer: (NSTimer *) aTimer {
NSLog(@"Bar: time over....");
if ([_delegate respondsToSelector:@selector(test:) ]) { [_delegate test: self]; } else { [NSException raise:NSInternalInconsistencyException format:@"Foo doesn't respond to selector"]; }
}
would appreciate any help.
regards,
Albert
|