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 に答える