0

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

4

2 回答 2

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];
于 2013-03-11T19:40:47.717 回答
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];
于 2013-03-11T19:40:57.700 回答