4

If a Delegate method is not getting called, then what all things needs to be checked just to ensure that delegate is referenced in the viewController?

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216

2 Answers2

5

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];
Aurum Aquila
  • 9,126
  • 4
  • 25
  • 24
0

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".

Girish
  • 4,692
  • 4
  • 35
  • 55
occulus
  • 16,959
  • 6
  • 53
  • 76