0

如果应用程序处于活动状态,我必须遵循代码来显示通知。我把它放在 AppDelegate.m

我想要做的是在用户点击第二个按钮时执行到视图控制器的转换(或转场)。我如何从 AppDelegate 执行此操作?

我想我需要将navigationcontroller 设置为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,这取决于您的应用程序有多少视图控制器。以简单的方式,您可以尝试将当前模态视图控制器调用到应用程序的根控制器: 1)添加到项目自定义 UIViewController(.h,.m,.xib)(示例名称:MyViewController)

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 回答