从基于窗口的项目开始建立基于导航的项目
只是想了解一下不同的项目类型是如何构建的,我一定错过了一些东西。
我尝试从基于窗口的应用程序开始,然后添加一个导航控制器,以便我了解不同的组件如何与窗口和应用程序委托一起工作。
这就是我所做的:
- 创建了一个基于 Window 的项目
- 在我的应用程序 delegate.h 中添加了
@property(nonatomic,retain)IBOutlet UINavigationController *navigationController;
在我的应用程序 delegate.m 中,我添加了:
@synthesize navigationController;
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
- 在 MainWindow.xib 文件中,我在下面添加了一个 NavigationController 窗口
- 创建了一个新的 UIViewController 子类 (FirstView.h/m)
- 将 NavigationController 的根视图控制器指向 FirstView
构建干净,当我启动时,我得到一个全白屏幕。
我缺少什么?
Just trying to wrap my head around how different project types are built and I must be missing something.
I'm trying to start with a window based application and just add a Navigation Controller so I understand how the different components work with the Window and App delegate.
Here's what I did:
- Created a Window based project
- In my app delegate.h I added
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
In my app delegate.m I added:
@synthesize navigationController;
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
- In the MainWindow.xib file I added a NavigationController below the
Window - Created a new UIViewController subclass (FirstView.h/m)
- Pointed the NavigationController's root view controller to FirstView
Builds clean, when I launch I get an all white screen.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
添加此
[self.window addSubview:self.navigationController.view];
您需要将导航控制器视图添加到窗口。还要确保导航控制器的插座已连接。您还需要为导航控制器添加根视图控制器Add this
[self.window addSubview:self.navigationController.view];
You need to add the navigation controllers view to the window. Also make sure that the outlet for the navigation controller is connected. You will also need to add root view controller for the navigation controller实际上Barfoon ..您的导航控制器不包含任何
uiviewController
。首先,创建新的uiviewController
,而不是将其添加到uinavigationController
。uinavigationController
就像堆栈一样,它处理每个添加的uiviewController,即“来回遍历”。前任..
Actually barfoon..your navigation controller does not contains any
UIViewController
. First of all create newUIViewController
and than add it toUINavigationController
.UINavigationController
is just like stack ,which handle each and every added UIViewController i.e traversing like back and forth.Ex..
想通了 - 我必须创建一个新的引用插座并将导航控制器连接到 .xib 中的应用程序委托。
Figured it out - I had to create a new Referencing outlet and connect the Navigation Controller to the App Delegate in the .xib.