从基于窗口的项目开始建立基于导航的项目

发布于 2024-12-05 07:01:32 字数 908 浏览 0 评论 0原文

只是想了解一下不同的项目类型是如何构建的,我一定错过了一些东西。

我尝试从基于窗口的应用程序开始,然后添加一个导航控制器,以便我了解不同的组件如何与窗口和应用程序委托一起工作。

这就是我所做的:

  • 创建了一个基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

筱果果 2024-12-12 07:01:32

添加此 [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

停滞 2024-12-12 07:01:32

实际上Barfoon ..您的导航控制器不包含任何uiviewController。首先,创建新的uiviewController,而不是将其添加到uinavigationControlleruinavigationController就像堆栈一样,它处理每个添加的uiviewController,即“来回遍历”。
前任..

ToDoController *toDoObj = [[ToDoController alloc] initWithNibName:@"ToDoController" bundle:[NSBundle mainBundle]];
UINavigationController *toDoNav = [[UINavigationController alloc] initWithRootViewController:toDoObj];
[self.window addSubview:toDoNav.view];

Actually barfoon..your navigation controller does not contains any UIViewController. First of all create new UIViewController and than add it to UINavigationController. UINavigationController is just like stack ,which handle each and every added UIViewController i.e traversing like back and forth.
Ex..

ToDoController *toDoObj = [[ToDoController alloc] initWithNibName:@"ToDoController" bundle:[NSBundle mainBundle]];
UINavigationController *toDoNav = [[UINavigationController alloc] initWithRootViewController:toDoObj];
[self.window addSubview:toDoNav.view];
策马西风 2024-12-12 07:01:32

想通了 - 我必须创建一个新的引用插座并将导航控制器连接到 .xib 中的应用程序委托。

Figured it out - I had to create a new Referencing outlet and connect the Navigation Controller to the App Delegate in the .xib.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文