问题描述
我有一个iPhone应用程序,该应用程序显示带有按钮的简单视图(视图1).当用户按下此按钮时,View 2会通过调用滑入视图
I have an iPhone app that shows a simple view (View 1) that has a button. When the user presses this button, View 2 slides into view using the call
[self presentModalViewController:self.view2 animated:YES];
我希望View 2支持导航控制器.我找到的所有代码都告诉您如何设置导航控制器应用程序,但是我不知道如何使用IB进行设置.
I want View 2 to support a navigation controller. All the code I find tells you how to set up a Navigation Controller App, but I can't figure out how to set this up using IB.
我所做的是创建一个普通的view2.xib文件.我将文件的所有者类设置为view2.我将导航控制器添加到XIB.我在UINavigationController的view2.h中创建了一个名为view2Nav的IBOutlet.我将view2Nav链接到view2.xib中的NavigationController.
What I have done is to create a plain view2.xib file. I set the file's owner class to view2.I add a navigation Controller to the XIB. I create an IBOutlet called view2Nav in view2.h for a UINavigationController. I link view2Nav to the NavigationController in view2.xib.
然后我用view3.xib创建一个view3类.我在view2.xib中将RootViewController设置为view3类,并将其NIB名称设置为view3.
I then create a view3 class with view3.xib. I set the RootViewController in view2.xib to be of class view3 and set its NIB name to view3.
然后我返回并运行该程序.当我在视图1上按我的按钮时,应用程序在尝试创建视图2时崩溃.
Then I go back and run the program. When I press my button on view 1, the app crashes as it tries to create view 2.
我知道我一定缺少设置或其他内容.
I know I must be missing a setting or something.
推荐答案
MySecondViewController *secondVC = [[MySecondViewController alloc] initWithNibName:@"MySecondViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondVC];
[self presentModalViewController:navigationController animated:YES];
[secondVC release];
[navigationController release];
忘记IB.在代码中执行任何操作:)速度更快,您将完全知道它为什么以及如何工作.
Forget about IB. Do anything in code :) It is faster and you will exactly know why and how it works.
我不确定您是否可以将self.view2
传递给presentModalViewController
.如果self.view2
是UIViewController
的子类,则可以.如果它是简单的UIView
,则不应该.如果事实上你根本不能做.
I'm not sure whether you can pass a self.view2
to presentModalViewController
. If self.view2
is a subclass of UIViewController
, you can. If it is a simple UIView
, you shouldn't. If fact you can't at all.
这篇关于您如何正确设置辅助视图以在iPhone上支持导航控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!