Reputation: 341
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
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
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
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
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