user3115233
user3115233

Reputation: 341

calling UIViewController through UITabBarController for push

In my app I have UINavigationController as initial view , Hierarchy is like this

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

MasterViewController has tableView in itself

when a push notification comes , I click on push notification while app is working at background , then app opens masterViewController, the problem is that I want to update tableList in MasterviewController when I open the app from push notification.

I try to navigate to MasterViewController from AppDelegate like this

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

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

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

    [masterController updateList];

    }

It is not working, How can I update MasterViewController when I get the push?

Thanx.

Upvotes: 1

Views: 341

Answers (4)

Kumar KL
Kumar KL

Reputation: 15335

This could work as well.

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

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

Upvotes: 1

Vidhyanand
Vidhyanand

Reputation: 993

Getting the tabbar view controllers and call that view method with 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;
                         }
                   }

Hope it will solve your issue....

Upvotes: 0

simalone
simalone

Reputation: 2768

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

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

Upvotes: 0

Bhumeshwer katre
Bhumeshwer katre

Reputation: 4671

You should try in this way:

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

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

Upvotes: 1

Related Questions