-2

i know this question had been asked before but after few search i did not find an answer for my query here is the scenario after presenting a view in a modally form the the simulator give me black screen as mentioned here: screen shot

here is the code that i am using :

    NSString *username = self.usernameTf.text;
    NSString *password  = self.passwordTf.text;
    if ([username isEqualToString:@"zakaria"] || [password     isEqualToString:@"zakaria"]) {
        adminViewController *avc = [[adminViewController alloc] init];
        UINavigationController *nav  = [[UINavigationController alloc]    initWithRootViewController:avc];
          [self presentViewController:nav animated:YES completion:nil];
    }

i already tried this solution Modal View with Navigation Controller but i got the same result any help guys

Edited for given solution i tried your solution but here is the result enter image description here and here is the story board that i use

enter image description here

Community
  • 1
  • 1
Zakaria Darwish
  • 358
  • 5
  • 22

3 Answers3

2

Ok you are using storyboard. It means your view controller init does not create view. So you should give Storyboard Id to your adminViewController. And then you should replace your adminViewController init

adminViewController *avc = [[adminViewController alloc] init];

With

adminViewController *avc =   [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"adminViewController"];

Then it should work fine.

But if you give storyboard id to your navigation controller you do not need to initialize any navigation controller. Storyboard will create both navigation and adminViewController.

[enter image description here]

kekkeme
  • 942
  • 1
  • 7
  • 10
0

You have to first place the UINavigation Controller in the Storyboard just on the ViewController on which you are calling this method

NSString *username = self.usernameTf.text;
        NSString *password  = self.passwordTf.text;
        if ([username isEqualToString:@"zakaria"] || [password     isEqualToString:@"zakaria"]) {
            adminViewController *avc = [[adminViewController alloc] init];

              [self presentViewController:avc animated:YES completion:nil];
        }

Then all this work fine.

Sucharu Hasija
  • 1,096
  • 11
  • 23
0

All is fine... You need to make navigation controller as root of your design. Currently you have Login as root. As login is root, there is no navigation controller for your design and hence your code is not working.

In-short, make navigation view controller as Is Initial View Controller

Even you don't need the below line in your code.

UINavigationController *nav  = [[UINavigationController alloc]    initWithRootViewController:avc];
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276