self.navigationController是' null'甚至在嵌入导航控制器之后

时间:2015-08-01 11:53:08

标签: ios uinavigationcontroller storyboard pushviewcontroller presentviewcontroller

我想将navigationcontroller添加到使用viewcontroller创建的现有storyboard,我已将其嵌入导航控制器中,但导航代码(如下所示)是即使嵌入导航控制器后也无法工作:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:@"EPVController"];
    [self.navigationController pushViewController:nextViewController animated:YES];

当我尝试记录self.navigationController时,会显示null

  

更新:我正在尝试presentViewcontroller时很好,但是我   想要viewcontroller推送navigationController

我正在为此奋斗两天,请帮助。

1 个答案:

答案 0 :(得分:0)

如果self是UINavigationController的子类,则不需要引用navigationController属性。 (请注意,如果EditProfileViewController也是UINavigationController的子类,这将无法工作,因为您无法在UINavigationController中推送UINavigationController。)

EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:@"EPVController"];
[self pushViewController:nextViewController animated:YES];

否则,如果您没有预先存在的导航控制器

EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:@"EPVController"];
[self presentViewController:nextViewController animated:YES completion:nil];