-1

I am trying to navigate from AppDelegate didViewLoadFinished function but I'm unable to succeed as I'm completely new to ios. I'm using a storyboard for ViewControllers.

I also checked the other solutions like this one : Swift - pushViewController from appDelegate, rootViewController.navigationController is nil but it didn't solve my problem.

Here is my ViewController on story Board: StoryBoard screenshot

Here is how I'm trying to load new ViewController "MultipleMarkersViewController":

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
            MultipleMarkersViewController *wc=[storyboard instantiateViewControllerWithIdentifier:@"MultipleMarkersView"];
            [self.window.rootViewController.navigationController pushViewController:wc animated:YES];

The expected result is to load the new ViewController. But is the actual result is "The App crashes" with following log output:

0   CoreFoundation                      0x000000010894f6fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000107ef3ac5 objc_exception_throw + 48
    2   UIKitCore                           0x00000001119f9624 +[UIStoryboard storyboardWithName:bundle:] + 675
    3   Runner                              0x00000001060b09bd __57-[AppDelegate application:didFinishLaunchingWithOptions:]_block_invoke + 909
    4   Flutter                             0x000000010614c9a2 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 115
    5   Flutter                             0x0000000106169616 _ZNK5shell21PlatformMessageRou<…>
5
  • 3
    You should use only "Main" for storyboard name. Replace "Main.storyboard" to "Main". Commented May 3, 2019 at 16:18
  • Now the crash is resolved but the app does not navigate to the next ViewController. What can be the possible reason. Commented May 3, 2019 at 16:32
  • Actually I'm complete new to IOS and I have to implement it in Objective-C. Commented May 4, 2019 at 5:23
  • Why did you need to navigate from appdelegate like this. If you need to show MultipleMarkersViewController as first view controller after launching app. Then you can easily do it by set to as initial view controller that's it. Or if you want to navigate from a rootviewcotnroller , Then first check that whether the root view controller has UInavigationcontroller or not. Commented May 4, 2019 at 13:31
  • Thank you so much! The Issue has been resolved. Commented May 4, 2019 at 16:28

2 Answers 2

0

When you are loading a storyboard, there is no need to add the extension ".storyboard" to the name of that. So, please use the following:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

And about your last line, I would prefer to use the following line, if you are loading your view from [AppDelegate didFinishLaunchingWithOptions]:

[self.window setRootViewController: wc]
Sign up to request clarification or add additional context in comments.

Comments

0

Here is how I resolved the issue after 24hrs of struggle. The only thing I tried was "Used Try Catch Block" and the error was that I was not using the correct identifier name which was causing null pointer exception. Here is the code:

@try {
                UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                MultipleMarkersVC *vc = [sb instantiateViewControllerWithIdentifier:@"MultipleMarkersVC"];
                UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vc];
                [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
            }
            @catch (NSException * e) {
                NSLog(@"Exception: %@", e);
            }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.