通过UITabBarController调用UIViewController进行推送

时间:2014-02-18 08:42:06

标签: ios iphone objective-c uiviewcontroller

在我的应用程序中,我将UINavigationController作为初始视图, 层次结构就像这样

  

的UINavigationController - > LoginViewController    - > UITabBarController - > UINavigationController - > MasterViewController

MasterViewController本身有tableView

当推送通知到来时,我点击推送通知,而应用程序在后台工作,然后应用程序打开masterViewController,问题是当我从推送通知打开应用程序时,我想在MasterviewController中更新tableList。

我尝试从AppDelegate导航到MasterViewController,就像这样

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

    UINavigationController * navController = (UINavigationController *) self.window.rootViewController;

    MasterViewController * masterController = [navController.viewControllers objectAtIndex:0];

    [masterController updateList];

    }

它不起作用,如何在推送时更新MasterViewController?

感谢名单。

4 个答案:

答案 0 :(得分:1)

你应该这样试试:

UINavigationController * navController = (UINavigationController *) self.window.rootViewController;
for (id viewController in navController.viewControllers) {
    if ([viewController isKindOfClass:[MasterViewController class]]) {

              MasterViewController * masterController = (MasterViewController*) viewController; 
              [masterController updateList];
             break;
    }
}

答案 1 :(得分:1)

这也可以。

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

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    MasterViewController * masterController = [storyboard instantiateViewControllerWithIdentifier:@"Your_StoryboardID"];
[masterController updateList];
}

答案 2 :(得分:0)

UINavigationController * navController = (UINavigationController *) self.window.rootViewController;

MasterViewController * masterController = [navController visibleViewController];
if ([viewController isKindOfClass:[masterController class]]) {
    [masterController updateList];
}
eles{
   //Hierarchy maybe not as your description
}

答案 3 :(得分:0)

获取tabbar视图控制器并使用pop ...

调用该视图方法
    NSArray *array=[self.tabBarViewController viewControllers];

                    for(int i=0;i<array.count;i++)
                    {

                        UINavigationController *navCont=[array objectAtIndex:i];
                        NSArray *navArray=[navCont viewControllers];
                        for (id view in navArray)
                        {
                            if ([view isKindOfClass:[MasterViewController class]])
                            {
                                MasterViewController * masterController =        (MasterViewController*) viewController; 
                                 [masterController updateList];

//if you want to pop to that view controller then use below two lines of code else put comments..

                                [self.tabBarViewController setSelectedIndex:0]; 
                                [navCont popToRootViewControllerAnimated:YES];
                            }
                            break;
                         }
                   }

希望它能解决你的问题......