If a Delegate method is not getting called, then wh开发者_StackOverflow中文版at all things needs to be checked just to ensure that delegate is referenced in the viewController?
Well, for a start you have to conform to the protocol in your header:
@interface MyViewController : UIViewController <YOUR DELEGATE'S PROTOCOL HERE,
UITableViewDelegate>{
}
@end
That's the most common mistake, anyway.
Also just make sure that you're setting your delegate. Normally you can do that like this:
myObject.delegate = self;
Though some classes do it in the initalization:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MY APP"
message:@"HELLO"
delegate:self
cancelButtonTitle:@"CLOSE"
otherButtonTitles:nil];
If delegate methods aren't getting called when you are expecting them to, it's possible that you haven't actually hooked up the delegate. This can be done either in code, or in interface builder. For example, a UITableView
in interface builder can have its dataSource
and delegate outlets attached to a target, for example "File's owner".
精彩评论