开发者

iPhone - App still running, receive push notification = change view

I'm trying to change view upon receive a push notification while the app is still running. I tried using this in the AppDelegate.m

-(void)application:(UIApplication *)application didRecieveNotification:(NSDictionary *)userInfo
{ 
   TestClass *aTestClassViewController = [[TestClass alloc]initWithNibName:@"TestClass" bundle:nil];
   [self presentModalViewController:aTestClassViewController animated:开发者_如何学CYES];
   [aTestClassViewController release];
}

But it didn't work. I can't even start up the app again. so I'm guessing this is the wrong way to do it.

Any idea guys? I would appreciate it.


Solved*** I did it this way -> I showed an alert view first (Which i needed anyways) then used the method of

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    TestClass *aSelectionScreenViewController = [[TestClass alloc] initWithNibName:@"TestClass" bundle:nil];
    [viewController presentModalViewController:aSelectionScreenViewController animated: YES]; 
    [aSelectionScreenViewController release];   }


We're missing some context about your application, but your basic problem is that it's the application delegate object which is receiving the notification, not a view controller. That's why you can't just do [self presentModalViewController:someViewController];

I think it's the snippet from your own answer that gives what you need: your app delegate (presumably) has a 'viewController' member, which is the root view controller for the application. It is that viewController object you need to prod into doing whatever it is you need. In the app I'm looking at right now, I have a tabBarController member in the app delegate, and I show an alert view and/or change the selected tab index when a notification comes in.

I would have your app delegate call a function on your main view controller when a message comes in, and have that function show the alert view, then do whatever state changes you need to do to make the main view controller reflect the received notification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜