设置UIAlertView委托

时间:2013-03-11 19:37:02

标签: ios xcode

我正在尝试使用此代码将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:期望的表达式”。这是什么意思?

2 个答案:

答案 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];