我正在尝试使用此代码将viewcontroller A委托给viewcontroller B中的UIAlertView:
在ViewcontrollerA.m
中-(IBAction)callCancelAlert:(id)sender{
ViewcontrollerB *controller = [[PhotoViewController alloc] init];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"It turns out that you are playing Addicus!"
delegate: PhotoViewController
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
//[alert release];
}
和#import ViewcontorllerB.h
...但我收到错误“意外的接口名称ViewcontorllerB:期望的表达式”。这是什么意思?
答案 0 :(得分:1)
您的委托需要是ViewControllerB的实例,而不是类。
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"It turns out that you are playing Addicus!"
delegate: PhotoViewController
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
到
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"It turns out that you are playing Addicus!"
delegate: controller
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
答案 1 :(得分:0)
您可能不是指delegate: PhotoViewController
,这意味着“将委托设置为PhotoViewController类”。
相反,你可能想要这个:
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"It turns out that you are playing Addicus!"
delegate:controller
cancelButtonTitle:@"OK"
otherButtonTitles:nil];