Using pushViewController: animated:

℡╲_俬逩灬. 提交于 2020-01-06 07:08:23

问题


I'm trying to use the pushViewController: animated: with a UIViewController. I have it housed in a UINavigationController with initWithRoot and it still doesn't work.

Here is my code? Am I doing something wrong?

CloudappSettingsViewController *cloud = [[CloudappSettingsViewController alloc] initWithNibName:nil bundle:nil];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cloud];
        [self pushViewController:nav animated:YES];
        [cloud release];

It always crashes when it gets up to the [self pushViewController:nav animated:YES];

Any ideas? Thanks


回答1:


is "self" a UINavigationController?

It seems you are trying to push the navigation controller, but that is backwards. You should present the navigation controller and push additional views to it.

So the UIView you are in should already be in the nav controller then you would push cloud into that.




回答2:


If this is in your app delegate, just add the UINavigationController as a subview to your app's window. If you want to present the UINavigationController as a modal view controller then do this:

[self presentModalViewController:nav animated:YES];



回答3:


It will crash definitely because you set the nib to nil.

CloudappSettingsViewController *cloud = [[CloudappSettingsViewController alloc] initWithNibName:@"NibName goes here" bundle:nil];

Create a nib and assign it to your view controller.



来源:https://stackoverflow.com/questions/5745541/using-pushviewcontroller-animated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!