为什么 SplitView iPhone 模板没有 RootView 的 nib 文件?
我正在深入研究 iPad 开发,并且学得很快,但我到处都有疑问。使用模板在 Xcode 中创建新的 SplitView 应用程序后,它会生成 AppDelegate 类、RootViewController 类和 DetailViewController 类。除此之外,它还为 MainWinow.xib 和 DetailView.xib 创建 .xib 文件。
- 这五个文件如何协同工作?
- 为什么 DetailView 有 nib 文件,而 RootView 没有?
- 当我双击 MainWindow.xib 文件时,Interface Builder 启动时没有“查看”窗口,为什么?
下面是 AppDelegate 类中
didFinishLaunchingWithOptions
方法的代码。为什么我们要添加 splitViewController 作为子视图?(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 应用程序启动后覆盖自定义点 rootViewController. ManagedObjectContext = self. ManagedObjectContext; // 将分割视图控制器的视图添加到窗口并显示。 [窗口addSubview:splitViewController.view]; [窗口 makeKeyAndVisible]; 返回是;
}
非常感谢您的帮助!我还有很多东西要学,所以如果这个问题有任何荒谬之处,我深表歉意。我现在要继续研究这些问题!
I'm diving into iPad development and am learning a lot quickly, but everywhere I look, I have questions. After creating a new SplitView app in Xcode using the template, it generates the AppDelegate class, RootViewController class, and DetailViewController class. Along with that, it creates a .xib files for MainWinow.xib and DetailView.xib.
- How do these five files work together?
- Why is there a nib file for the DetailView, but not the RootView?
- When I double click on the MainWindow.xib file, Interface Builder launches without a "View" window, why?
Below is the code for
didFinishLaunchingWithOptions
method inside the AppDelegate class. Why are we adding the splitViewController as a subview?(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after app launch rootViewController.managedObjectContext = self.managedObjectContext; // Add the split view controller's view to the window and display. [window addSubview:splitViewController.view]; [window makeKeyAndVisible]; return YES;
}
Thanks so much in advance for all your help! I still have a lot to learn, so I apologize if this question is absurd in any way. I'm going to continue researching these questions right now!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MainWinow.xib 是每个 Cocoa touch 项目创建的默认窗口。这是所有其他窗口都添加到的窗口,通常在 AppDelegate 中。
AppDelegate,我假设您已经知道了。这是您的应用程序的基类。
SplitViewController 是一个 UISplitViewController,它会使用 IB 添加到 MainWindow.xib 中,但在运行 didFinishLaunchingWithOptions: 之前不会添加到 MainView.xib 中的窗口。
默认情况下,SplitViewController 管理两个 ViewController,以方便您。通常这些是 UITableView(在模板中称为 RootViewController)和 UIViewController(称为 DetailViewController)。尽管您可以根据需要完全删除它们。
RootViewController 只是一个 UITableViewController。它被添加到IB中的SplitViewController中。
DetailViewController是一个UIViewController,它也被添加到MainWindow.xib中的IB中。
我相信 DetailView 是从 nib 文件加载的,以方便内存管理。但它也可以很容易地以编程方式创建。 RootView 没有笔尖,因为它已在 UISplitViewController 中添加并初始化。它可以很容易地从 xib 文件加载。
此默认 iPad 模板使用名为 SplitViewController 的 UISplitViewController,而不是像其他 iPhone 模板那样使用名为 View 的 UIView。
SplitViewController仅存在于MainWindow.xib中,它没有添加到Window(在MainWindow.xib中)。所以在这里添加一下。如果它嵌套在 SplitViewController 中,则无需添加到 AppDelegate 中。
这是您想要阅读的文档
MainWinow.xib is the default window created by every Cocoa touch project. It's the window all other windows are added to, usually in the AppDelegate.
AppDelegate, I'm assuming you know already. This is your base class for your Application.
SplitViewController is an UISplitViewController and it is added to MainWindow.xib for you using IB, but not added to the Window in MainView.xib until didFinishLaunchingWithOptions: is run.
By default SplitViewController manages two ViewControllers as a convenience for you. Typically these are a UITableView (called RootViewController in the template), and a UIViewController (called DetailViewController). Although you can remove these entirely if you want.
RootViewController is simply a UITableViewController. It is added to SplitViewController in IB.
DetailViewController is a UIViewController, and it is also added to IB in MainWindow.xib for you.
I believe DetailView is loaded from a nib file to facilitate memory management. But it just as easily could have been created programmatically. There is not a nib for the RootView because it is already added and initialized in UISplitViewController. It could have just as easily been loaded from a xib file.
This default iPad template uses a UISplitViewController called SplitViewController and not a UIView Called View as other iPhone templates.
SplitViewController only exists in the MainWindow.xib, it's not added to Window (in MainWindow.xib). So it is added here. If it were nested in SplitViewController there would be no need to added in the AppDelegate.
This is the document you want to read