Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Programmatically changing views within AppDelegate

I'm attempting to change a view when specific push notifications come through, I've had minor success. (Using parse with push notifications, catering for when the App is open and closed).

My Storyboard looks like this, I'm attempting to change the view within AppDelegate to DetailViewController. enter image description here

Now I'm able to change views by changing the root controller, but I've only been able to attach either my tab view or the navigation not both.

 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    DetailViewController *detail = (DetailViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"detail"];
    [detail setDetailItem:StreamData[2]];

    self.window.rootViewController = detail;

And of course the use of (below) only works in other controllers.

[self.navigationController pushViewController:detail animated:YES];

I'm wondering if this can be achieved from AppDelegate while maintaing the tabbar at the bottom and the navigation at the top?

My initial work around is to set a trigger from the AppDelegate to a global var accessible from all controllers and then use something like viewDidAppear to check if they view needs to change. This seems way too resource intensive though but it maintains my layouts.

My issue is similar to this: pushing view controller inside a tab bar from app delegate, after a notification

like image 381
Tom Avatar asked Feb 01 '26 20:02

Tom


1 Answers

I have done a work around in your problem. Created some scene's,not sure it going to work in your case. Anyway give a try

My storyboard

enter image description here

What I have done

 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

[(UITabBarController *)self.window.rootViewController setSelectedIndex:1];
UINavigationController *nav = [[(UITabBarController *)self.window.rootViewController viewControllers]objectAtIndex:1];
UIViewController *detail = [mainStoryboard instantiateViewControllerWithIdentifier:@"detail"];
[nav pushViewController:detail animated:NO];

This gives me the detail view controller with a button as the first view with tab bar and navigation controller

like image 159
Anil Varghese Avatar answered Feb 03 '26 10:02

Anil Varghese