[英]viewcontroller - how to get another root view controller / how to switch Views
I'm having problems understanding where the object viewController
comes from. 我在理解对象viewController
来源时遇到了问题。 I have an existing app that provides a detail view, and I need to put a table view in front of that to be able to choose a specific detail view. 我有一个提供详细视图的现有应用程序,并且需要在其前面放置一个表格视图才能选择特定的详细视图。 The app starts with 该应用开始于
self.window.rootViewController = self.viewController;
And I just don't get where (self.)viewController
comes from. 而且我只是不知道(self.)viewController
来源。 It's a property of my app delegate and it's in the .m
-file of the app delegate: 这是我的应用程序委托的属性,并且在应用程序委托的.m
文件中:
@synthesize viewController=_viewController;
But I have no idea how the app knows, which viewController
this is, because there seems to be no "assignment" or "creation" of the actual viewController
object. 但是我不知道应用程序如何知道这是哪个viewController
,因为实际的viewController
对象似乎没有“分配”或“创建”。 And how would I move my tableView "in front" of the existing viewController
? 以及如何将tableView移动到现有viewController
“前面”?
Thanks in advance! 提前致谢!
In nib-based projects there is a key in Info.plist
named NSMainNibFile
, or “Main nib file base name”, that instructs UIApplication
to load MainWindow.xib
and hook it into the app. 在基于笔尖的项目中, Info.plist
有一个名为NSMainNibFile
或“ Main nib file base name”的密钥,它指示UIApplication
加载MainWindow.xib
并将其挂接到应用程序中。
So if you look in MainWindow.xib
(or whatever xib is referenced in the Info.plist
NSMainNibFile
entry), you'll see a view controller. 因此,如果您查看MainWindow.xib
(或Info.plist
NSMainNibFile
条目中引用的任何xib),您将看到一个视图控制器。 If you click on the view controller in the document outline (panel on the left of the xib view), you can change it's class in the Identity Inspector ( Command + Option + 3 , which pulls up the Identity Inspector in the right panel). 如果单击文档大纲中的视图控制器(xib视图左侧的面板),则可以在Identity Inspector中更改它的类( Command + Option + 3 ,在右侧面板中拉起Identity Inspector)。
It's a little different with storyboards - the main nib key in Info.plist
is now replaced with a main storyboard key, and the View Controllers now appear below each panel in the storyboard rather than in the document organizer - but it's basically the same idea. 这是故事板稍有不同-在主笔尖关键Info.plist
目前正与主要故事板键取代,并在视图控制器,现在出现在故事板,而不是在文件管理器的每个面板的下方-但它基本上是相同的想法。
The xib/storyboard file is compiled to code that allocs a UIViewController
instance at startup and assigns the instance to the viewController
variable. xib / storyboard文件被编译为在启动时分配UIViewController
实例并将该实例分配给viewController
变量的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.