0

On my xcode project I have a some views and a tab bar controller. When I open my app the first view comes up. I have also a server that sends to the app some push notifications.

I use on AppDelegate.m:

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {

    for (id key in userInfo) {
        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);

     }
}

My question is: how can I open a specific view (in this case is called "AnswerDetailsVC") when I open the notification? The specific view is opened from the 4th view on the tabbar.

4

1 回答 1

0

If you detect your push notifications payload is the right one to open the AnswerDetailsVC, just set selected tab of tabbar like this:

//  Open 4th tab in tabbar
self.tabBarController.selectedIndex = 3;

Edit: You can access controller at given tab and call any public method you want. So you can call button action manually or prepare public method which makes what you want to do after the notification and call it when you receive notification

Example code:

//  Get controller at given tab
AnswerDetailsVC *myController = (AnswerDetailsVC *)[[self.tabBarController viewControllers] objectAtIndex:2];
//  Call button action or whatever public method you want
[myController buttonAction:nil];
于 2013-06-10T14:51:55.953 回答