0

アプリがアクティブな場合に通知を表示するには、次のコードを実行する必要があります。AppDelegate.mに入れました

私がやりたいことは、ユーザーが 2 番目のボタンをタップしたときに、viewcontroller への遷移 (またはセグエ) を実行することです。AppDelegate からこれを行うにはどうすればよいですか?

私はナビゲーションコントローラーをappdelegateに設定する必要があると思います..しかし、私はこれを達成できませんでした。

ありがとう

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive) {
        NSString *cancelTitle = @"Close";
        NSString *showTitle = @"Show";
        //NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Social Dilemma"
                                                            message:@"Next round is ready to play!"
                                                           delegate:self
                                                  cancelButtonTitle:cancelTitle
                                                  otherButtonTitles:showTitle, nil];
        [alertView show];
    }
}

-(void) alertView: ( UIAlertView *) alertView
clickedButtonAtIndex: ( NSInteger ) buttonIndex {
    if (alertView.tag == 1)
    {
        //check the button index
        //create and display the other alert view (set the tag property here to 2)
    }
    else if (alertView.tag == 2)
    {

    }
}
4

1 に答える 1

0

オプションとして、uinavigationcontroller を使用できます。これは、アプリのビュー コントローラーの量によって異なります。簡単な方法で、現在のモーダル ビュー コントローラーをアプリのルート コントローラーに呼び出してみることができます。

2 )

-(void) alertView: ( UIAlertView *) alertView
    clickedButtonAtIndex: ( NSInteger ) buttonIndex {
    if (alertView.tag == 1)
    {
       //check the button index
       //create and display the other alert view (set the tag property here to 2)
       MyViewController *first = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
       [self.window.rootViewController presentModalViewController:first animated:YES];
        [first release];
    }
    else if (alertView.tag == 2)
   {
         MyViewController *second = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
       [self.window.rootViewController presentModalViewController:second animated:YES];
        [second release];
   }
 }

uinavigation コントローラーを使用する場合、アプリケーション didFinishLaunchingWithOptions: でナビゲーション コントローラーをプログラムで作成し、それをルート コントローラーに割り当てて、アラート ビューのメソッド呼び出しで呼び出すことができます。

[self.window.rootViewController pushViewController:second (first) animated:YES];
于 2012-08-05T11:00:56.380 に答える