2012-08-05 3 views
0

Je dois suivre le code pour afficher une notification si l'application est active. Je l'ai mis dans AppDelegate.mEffectuer une transition après avoir appuyé sur un bouton de notification

Ce que je veux faire est d'effectuer une transition (ou segue) à un contrôleur de vue lorsque l'utilisateur appuie sur le second bouton. Comment puis-je faire cela depuis AppDelegate?

Je pense que j'ai besoin de configurer le contrôle de la navigation à appdelegate .. Mais je ne pouvais pas réaliser cela.

Merci

- (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) 
    { 

    } 
} 

Répondre

0

En option, vous pouvez utiliser UINavigationController, cela est dépend comment contrôleurs beaucoup la vôtre vue app a. De manière simple, vous pouvez invoquer présent contrôleur de vue modal au contrôleur racine de l'application: 1) Ajouter au projet sur mesure UIViewController (.h, .m, .xib) (nom Exemple: 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]; 
    } 
} 

pour utiliser le contrôleur de uinavigation, dans didFinishLaunchingWithOptions d'application: vous pouvez créer par programme contrôleur de navigation, assigner au contrôleur racine et dans la méthode de vue alerte invoquer

[self.window.rootViewController pushViewController:second (first) animated:YES]; 
Questions connexes