来自 appDelegate 的 UINavigationcontroller initWithRootViewController,空视图?
我遇到了问题。
我想用 UIViewController 初始化 UINavigationcontroller。当我的 Viewcontroller 从 .xib 加载时,我正在使用
UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:appDelegate.myViewController];
[selfpresentModalViewController:myNavigationControlleranimated:YES];
不幸的是我的观点是空的。
我做错了什么还是有其他方法实现我的目标?
如果我像这样分配 Viewcontroller 的实例
UIViewController *aController = [[UIViewController alloc] initWithNibName:@"myViewController" bundle:[NSBundle mainBundle]];
并且在笔尖内有一个按钮,那么我的应用程序在点击它时会崩溃。
多谢。
I ran into a problem.
I want to initialize an UINavigationcontroller with an UIViewController. As my Viewcontroller gets loaded from a .xib I am using
UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:appDelegate.myViewController];
[self presentModalViewController:myNavigationController animated:YES];
Unfortunately my view is empty.
Am I doing something wrong or is there an other way achieving my aim?
If I am allocating an instance of my Viewcontroller like so
UIViewController *aController = [[UIViewController alloc] initWithNibName:@"myViewController" bundle:[NSBundle mainBundle]];
And having a button inside the nib, my app crashes when tapping on it.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
myViewController *aController = [[myViewController alloc] initWithNibName:@"myViewController" 包:[NSBundle mainBundle]];
或
UIViewController *aController = [[myViewController alloc] initWithNibName:@"myViewController" bundle:[NSBundle mainBundle]];
然后推送它
,因为
如果你像这样输入
UIViewController *aController = [[UIViewController alloc] initWithNibName:@"myViewController" bundle:[NSBundle mainBundle]];
你分配 UIViewController 并且不知道默认 UIViewcontroller 中的按钮,
这意味着没有 UIButton 属性。
所以它崩溃了
myViewController *aController = [[myViewController alloc] initWithNibName:@"myViewController" bundle:[NSBundle mainBundle]];
or
UIViewController *aController = [[myViewController alloc] initWithNibName:@"myViewController" bundle:[NSBundle mainBundle]];
then push it
since
if u type like this
UIViewController *aController = [[UIViewController alloc] initWithNibName:@"myViewController" bundle:[NSBundle mainBundle]];
u allocating UIViewController and doesn't know about ur button in default UIViewcontroller
which means does n't have UIButton property.
so it crashes