所以我试图使用导航控制器从一个UIViewController切换到另一个。我确信新控制器成功通过自定义init方法并创建了两个UIBarButtons。但是,屏幕内容(4个标签,3个文本字段,1个UIImageView)没有显示出来。相反,我只看到一个灰色的屏幕。
通过ViewDidLoad,ViewWillLoad和ViewWillAppear传递NSLog消息,表明所有这些消息都已成功执行。
如果你想看一下,这是gitHub回购: https://github.com/Killavata/Class_Discussion/tree/Stepan
以下是我用来传递新控制器的代码:
// 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];
答案 0 :(得分:0)
你在故事板中创建了控制器,所以除非你从那里实例化它(使用segue或instantiateViewControllerWithIdentifier :),你将无法获得它的视图。如果要使用自定义init方法,则需要在代码中(在loadView中)创建整个UI,或者在xib文件中创建视图,加载该nib,并将视图设置为控制器的self.view。
另一种方法是不使用自定义init方法。创建一个属性isNew,并在实例化控制器之后但在呈现之前设置其值。在viewDidLoad中检查它的值,并将您现在拥有的代码放在viewDidLoad中的init方法中。