0

I have a library project, and an app project (that uses the library project).

For a particular method of a library, it will check if user exists in the system or not then popup a pre-created form to let user registers. But this is no direct way as it needs to show this form on behalf of the user's application thus an app project in this case.

App project has one storyboard (utilize UINavigationController). A library project also has one storyboard which contains independent UIViewControllers ie. registration form etc allowing user's application to invoke via library's method to show them during runtime.

I bundle the library's storyboard, and I can access it successfully in app project. The code below shows when I got response back, and tries to show registration form which is not success.

So the question is how to properly show UIViewController from another Storyboard as a modal on top of current UIViewController (in this case UINavigationController).

    // check if user exists in the system or not
    [self player:playerId withBlock:^(PBPlayer_Response *player, NSURL *url, NSError *error) {
        // user doesn't exist
        if(player == nil && error != nil && error.code == 200)
        {
            NSLog(@"Player doesn't exist");

            dispatch_async(dispatch_get_main_queue(), ^{
                // get the bundle from the library
                NSBundle *pbBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle]  URLForResource:@"pblibResource" withExtension:@"bundle"]];

                // get playbasis's storyboard
                UIStoryboard *pbStoryboard = [UIStoryboard storyboardWithName:@"PBStoryboard" bundle:pbBundle];

                // get regis ui-view-controller
                pbUserRegistrationFormViewController *regisForm = [pbStoryboard instantiateViewControllerWithIdentifier:@"registrationFormViewController"];

                // ----> show registration form - didn't show the form!
                [[[[UIApplication sharedApplication].keyWindow rootViewController] navigationController] presentViewController:regisForm animated:YES completion:nil];
            });
        }
        // player exists
        else if(player != nil && error == nil)
        {
            ...
        }
        // error
        else
        {
            ...
        }
    }];
haxpor
  • 2,431
  • 3
  • 27
  • 46
  • A navigation controller is a container. I would present it on top of the top view controller within the navigation controller. – dasdom Feb 14 '15 at 10:34
  • @dasdom Thank you. I tried this as per your suggestion [[[[[UIApplication sharedApplication].keyWindow rootViewController] navigationController] visibleViewController] presentViewController:regisForm animated:YES completion:nil]; but it didn't show anything. – haxpor Feb 14 '15 at 10:52
  • 1
    No, I mean: `[self presentViewController:regisForm animated:YES completion:nil];` – dasdom Feb 14 '15 at 12:08
  • @dasdom It works! Thank you. It would be nice though to get the current visible UIViewController and act on behalf of it without a need to push a code within the class to present it but as I come across http://stackoverflow.com/questions/11637709/get-the-current-displaying-uiviewcontroller-on-the-screen-in-appdelegate-m, there's no easy way. So I use your solution :) – haxpor Feb 14 '15 at 12:30

0 Answers0