0

I'm trying to work on a simple login application which on successful login displays a menu page. On the action sheet of menu page, we have an option of looking at all the users logged in that phone and clicking on any user, it should do some login processing and direct to menu page again. This is how the workflow should go on.

Below is the image that explains it.

enter image description here

All the controllers are connected to segues except for accounts controller and middle controller. Navigation between those two is done using pushViewController as I had to pass some info from accounts controller(table view controller with list of all users) to middle Controller.

 MiddleController *maController = [[MiddleController alloc] init];
        if (maController.view) {
            maController.ma_userId = mo_userId; // Set the exposed property
            maController.ma_password = mo_password;
        [self.navigationController pushViewController:maController animated:YES];

Middle controller is doing all the process perfectly after getting the details. But directing to menu controller is where I'm facing the problem. If I use a segue between middle controller and menu controller an error is thrown saying no identifier with the name segueName found. But if I use a pushViewController then it is displaying a blank black screen. Can some help me to solve this.

This is how I'm pushing it:

 MenuTableViewController *mapMenuTableviewController = [[MenuTableViewController alloc]init];
        [self.navigationController pushViewController:mapMenuTableviewController animated:NO];

I've tried all the ways that are posted in previous SO questions, but nothing helped.

Thanks in advance

ASN
  • 1,655
  • 4
  • 24
  • 52

5 Answers5

1

Try not to alloc-init, but instantiate it fom storyboard like this (you should add it a storyboard id)

YourViewControllerClass *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];

And then push it.

Ilya V.
  • 106
  • 6
  • @IIya : can you explain what do you mean by `you should add it a storyboard id`. – ASN Aug 05 '16 at 07:02
  • Please, look this question: http://stackoverflow.com/q/13867565/6562596 – Ilya V. Aug 05 '16 at 07:08
  • in my case, i should define the storyboardID for menu controller right? – ASN Aug 05 '16 at 07:19
  • its working IIya. thanks for the answer.. But because it has to pass through middle controller in between it should showing a black screen for a fraction and then showing the menu controller. How can i avoid this? – ASN Aug 05 '16 at 07:27
  • Easy workaround will be to change your middle controllers view background color to match your apps theme. But it is not best solve of this problem. Probably you should get rid of this controller at all. – Ilya V. Aug 05 '16 at 07:30
  • ok. thanks. But actually I have a label saying loading please wait. But it is not being displayed. May be I should do the same thing (instantiate from storyboard) to load this page. – ASN Aug 05 '16 at 07:33
  • Then use the same technique to instantiate it fom storyboard, not alloc-init – Ilya V. Aug 05 '16 at 07:38
1

You need to add storyboard id like this

enter image description here

And use like

UIViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewControllerID"];
Mahendra
  • 8,448
  • 3
  • 33
  • 56
1

Go to your storyboard, and set an identifier like this :

enter image description here

Now, in your view controller, do this :

YourViewController *viewController = [[UIStoryboard storyboardWithName:@"<your storyboard name>" bundle:nil] instantiateViewControllerWithIdentifier:@"myViewControllerID"];
[self.navigationController pushViewController:viewController animated:NO];

UPDATE -

Push you Accounts view controller and Middle view controller the way i told before.

Then, when your processing is done in the middle controller, just do this :

  [[self presentingViewController]presentingViewController]dismissViewControllerAnimated:NO completion:nil];
iOS Geek
  • 4,825
  • 1
  • 9
  • 30
  • in my case, i should define the storyboardID for menu controller right? – ASN Aug 05 '16 at 07:19
  • Yes, use it for the view controllers where you are not using segues for presenting. (here, your accounts and middle controller) – iOS Geek Aug 05 '16 at 07:21
  • yeah.. Its working.. Thanks for the answer. But because it has to pass through middle controller in between it should showing a black screen for a fraction and then showing the menu controller. – ASN Aug 05 '16 at 07:23
  • @ASN - why don't you simply dismiss your last two controllers, it will take you back to your menu view. I will update my answer. – iOS Geek Aug 05 '16 at 07:37
  • @ASN - Check my answer now and see if it helps you out with the black screen issue. :) – iOS Geek Aug 05 '16 at 07:50
  • instead I just used the same storyboarding way to instantiate and added a label in the middle controller view saying "Loading". will try this answer too.. should I add your answer just before calling the push view controller? – ASN Aug 05 '16 at 08:01
  • @ASN - push your account and middle controllers the way i told with the storyboard. Then just use this one line code i have put in my updated answer to move from middle view controller to menu view controller. No need to push here, just dismiss. – iOS Geek Aug 05 '16 at 08:04
0

Add storyboard Id to yput interface builder "SendSMSViewController" and call below code.

let SendSmsVC = self.storyboard?.instantiateViewControllerWithIdentifier("SendSMSViewController") as! SendSMSViewController

    self.navigationController?.pushViewController(SendSmsVC, animated: true)
Chirag Patel
  • 1,453
  • 1
  • 11
  • 21
0

Plz use this code you will go to MenuTableViewController.

  for (UIViewController *controller in self.navigationController.viewControllers)
                    {
                        if ([controller isKindOfClass:[MenuTableViewController class]])
                        {
                            [self.navigationController popToViewController:controller animated:YES];

                            break;
                        }
                    }
balkaran singh
  • 2,754
  • 1
  • 17
  • 32