Acan1234 Acan1234 - 4 months ago 15
Objective-C Question

pushfrontviewcontroler open blank screen

I need to set to root for second view controller through

SWRevealViewController
. But when I call
pushFrontViewcontroler
it become a blank screen. All my label that I defined in storyboard is missing. But the external xib i include is properly display. Am I missing something? Please enlighten me on how to solve this. Below is the code i use to call the second view controller.

SWRevealViewController *revealController = self.revealViewController;

ImageDetailViewController *imageViewController = [[ImageDetailViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imageViewController];

[revealController pushFrontViewController:navigationController animated:YES];


I also try using this but still failed

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imageViewController];

[self.revealViewController setFrontViewController:navigationController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];


Storyboard

Answer

Your main problem is the instantiation of your imageViewController

ImageDetailViewController *imageViewController = [[ImageDetailViewController alloc] init];

if you do something like this

ImageDetailViewController *imageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MyImageViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imageViewController];
[revealController pushFrontViewController:navigationController animated:YES];

this works perfect, but I still recommends you have your navViewControllers on your storyboard and change them like this code

     - (void) goMainViewControllerAction
    {
    UINavigationController* navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@“MainNavViewController”];
    [self.revealViewController pushFrontViewController:navigationController   animated:YES];
     }
  //

- (void) goImageViewControllerAction
    {
       UINavigationController* navigationController = [self.storyboard    instantiateViewControllerWithIdentifier:@"MyImageNavViewController"];
       [self.revealViewController     pushFrontViewController:navigationController animated:YES];
    }

I hope this helps you

Comments