2012-08-05 63 views
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) 
    { 

    } 
} 

回答

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];