user2080841
user2080841

Reputation: 221

PushViewController Leads To Black Screen

SettingsViewController *viewController = [[SettingsViewController alloc] init];
    [[self navigationController] pushViewController:viewController animated:YES];

When using this code in a NavigationController the scene shown is just a black screen. In storyboard it shows the content but it is not displayed on the phone.

Upvotes: 12

Views: 8930

Answers (7)

JingJingTao
JingJingTao

Reputation: 1790

so you could initialise using the name of the xib or storyboard as everyone is suggesting and that’s valid.

Although if you’re using storyboards and your initial viewcontroller is on the storyboard, they maybe rather do the following,

// Method in your initial viewcontroller 
- (void)youPushMethod { 

// Name your segue on your storyboard, e.g. SegueIndentifier 
[self performSegueWithIdentifier:@"SegueIndentifier" sender:self];
}

Then,

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

     if ([segue.identifier isEqualToString:@“SegueIndentifier"]) {
     SettingsViewController *settingsViewController= segue.destinationViewController;
    }
}

Upvotes: 0

Kumar C
Kumar C

Reputation: 553

Hi You've to set the top bar property (navigation bar) to inferred for the view controller. In my case I previously set the top bar as "Translucent navigation bar"

Usually this happens you perform a segue from a modal view controller.

Upvotes: 0

Tristan Richard
Tristan Richard

Reputation: 4065

An easy way to do it is by instantiate with the storyboard. You must give your viewcontroller a Storyboard ID and then use the following code:

YourView *view = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewID"];

When this is done simply push:

[[self navigationController] pushViewController:view animated:YES];

Hope this helps.

Upvotes: 1

svvoff
svvoff

Reputation: 289

I solved this problem by custom initialisation of destination view controller.

Your destination view controller:

-(id) initWithSender:(UINavigationController*)sender
{
        self=[sender.storyboard instantiateViewControllerWithIdentifier:@"DestinationVCIdentifier"];
    if (self) {
        //custom initialisation
    }
    return self;
}

And using it:

DestinationVC *viewController = [[SettingsViewController alloc] initWithSender:self.navigationController];
[[self navigationController] pushViewController:viewController animated:YES];

Upvotes: 0

Waseem Shah
Waseem Shah

Reputation: 2219

try this

  SettingsViewController *viewController = [[SettingsViewController alloc]initWithNibName:@"SettingsViewController" bundle:[NSBundle mainBundle]]; 
  [self.navigationController pushViewController:viewController animated:YES];

Upvotes: 0

shivam
shivam

Reputation: 1140

Try this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
SettingsViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"setting"];
[self.navigationController pushViewController:viewController animated:YES];

Set the settingviewcontroller's identifier to "setting"

Upvotes: 18

Vishal
Vishal

Reputation: 8256

Use this:

SettingsViewController *viewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:[NSBundle mainBundle]]; 
[[self navigationController] pushViewController:viewController animated:YES];

Upvotes: 1

Related Questions