Question

I would like to open a specific UIViewController depending on an id I get from a URL scheme.

For exemple myapp://news/285 would open the UIViewController "news" displaying this specific one.

I get notified here :

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)source
         annotation:(id)annotation
{   
    if ([[url scheme] isEqualToString:@"myapp"]) {

        NSString *urlString = url.absoluteString;

...

        return YES;
    }

    return NO;
}

But how am I supposed to push the UIViewController ? I can't access to the navigation controller from here.

(I was thinking about sending a notification with NSNotficationCenter to my home page with the id, and pushing the UIViewController from there. What do you think ?)

Thx

Was it helpful?

Solution

You know you view setup. So when you rootViewController is a UINavigationController then you can just use:

UINavigationController *navCon = (UINavigationController*)self.window.rootViewController;
[navCon pushViewController:myPushedVC animated:NO];

If not then maybe it is easier to go with the Notification approach

OTHER TIPS

You could achieve that sending a notification through NSNotificationCenter. Your view controller could catch that notification and push the other view controller.

If you are using a Tab bar, then use following code.

UINavigationController *navigationController = (UINavigationController *) tabBar_Controller.selectedViewController;

you can set the selected view controller as per your requirement.

If you are not using a tabbar

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

Now you can push to any view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top