0

私のアプリケーションでは、プッシュ通知機能を実装しており、通知を受け取っています。appDelegate ファイルで次のコードを使用しました。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    for (id key in userInfo) {
        NSMutableArray *array = [userInfo objectForKey:key];
        NSString *message = [NSString stringWithFormat:@"%@",[array valueForKey:@"alert"]];
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"iPhoneApp" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        [alert show];
        [alert release];
    }    
}

プッシュ通知アラート(アプリ起動時)のOKボタンクリックイベントでアクションを起こしたい。このアプリには 3 つのビュー コントローラーがあります。したがって、どのクラスにコードを追加する必要がありますか

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex?

4

1 に答える 1

0

delegateその特定の UIAlertViewとして設定した同じクラスで。あなたの現在のケースでは、AppDelegateは のレシーバーです-clickedButtonAtIndex:

あなたが持っている3つのコントローラーの1つでクリックイベントを受け取りたい場合。その特定のコントローラーをデリゲートとして次のように設定する必要がありますUIAlertView

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"iPhoneApp" message:message delegate:myViewController cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [alert show];
    [alert release];

ご覧のとおり、私myViewControllerは代理人として割り当てられました。プロトコルにmyViewController準拠し、メソッドを実装する必要があります。いずれかのボタンを選択すると、 で電話がかかります。UIAlertViewDelegate-clickedButtonAtIndex:myViewController

于 2012-06-12T09:15:41.137 に答える