iPhone SDK:没有调用Delegate方法 - 疑难解答

Par*_*att 4 iphone cocoa-touch delegates objective-c ios4

如果没有调用Delegate方法,那么需要检查所有内容以确保在viewController中引用委托?

Aur*_*ila 5

好吧,首先,你必须遵守标题中的协议:

@interface MyViewController : UIViewController <YOUR DELEGATE'S PROTOCOL HERE, 
UITableViewDelegate>{ } @end
Run Code Online (Sandbox Code Playgroud)

无论如何,那是最常见的错误.

还要确保你正在设置你的代表.通常你可以这样做:

myObject.delegate = self;
Run Code Online (Sandbox Code Playgroud)

虽然有些课程在初始化中做到了:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MY APP"
message:@"HELLO"
delegate:self
cancelButtonTitle:@"CLOSE"
otherButtonTitles:nil];
Run Code Online (Sandbox Code Playgroud)