UIViewController content not showing even if UINavigation panel

So I am trying to switch from one UIViewController to another using a navigation controller. I know for a fact that the new controller successfully goes through its own init method and creates two UIBarButtons. However, the screen content (4 labels, 3 text boxes, 1 UIImageView) is not displayed. Instead, I see a gray screen.

Passing the NSLog message through ViewDidLoad, ViewWillLoad and ViewWillAppear showed that they were all successful.

Here is the gitHub repository if you want to take a look: https://github.com/Killavata/Class_Discussion/tree/Stepan

Here's the code I'm using to pass the new controller:

// Create a new student and add it to the store
  Student* newStudent = [[StudentStore sharedStore] createStudent];

StudentDetailViewController *detailViewController = [[StudentDetailViewController alloc] initForNewStudent:YES];

detailViewController.student = newStudent;

detailViewController.dismissBlock = ^{
    [self.tableView reloadData];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

navController.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentViewController:navController animated:YES completion:NULL];



source to share

1 answer

You've made the controller in the storyboard, so if you don't create it there (with segue or instantiateViewControllerWithIdentifier :) you won't get a view of it. If you want to use your own init method, you need to either make the entire UI in code (in loadView), or make the view in the xib file, load that nib and set the view to the self.view of the controller.

Another approach is to not use a custom init method. Create an isNew property and set its value after the controller is instantiated, but before presenting it. Check its value in viewDidLoad and put the code you now have in init method in viewDidLoad.



All Articles