简体   繁体   English

viewcontroller-如何获取另一个根视图控制器/如何切换视图

[英]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.

相关问题 如何在UITabBarItem开关上弹出到根视图控制器? - How to pop to root view controller on UITabBarItem switch? 如何将NSMutableDictionary从一个viewController传递到另一个View控制器? - How to pass NSMutableDictionary from one viewController to another View controller? iOS:如何从另一个视图控制器调用根控制器 - iOS: How to call root controller from another view controller 如何在没有情节提要ID的情况下迅速为导航控制器设置根视图控制器。 并导航到其他视图,仅使用viewcontroller名称 - How to set root view controller for a navigation controller in swift without storyboard id. And navigate to other view Only with viewcontroller name 我如何选择另一个与当前根控制器共享相同根控制器的viewController? - How do I segue to another viewController that shares the same root controller as the current one? 如果表行中的某些值已更新,如何切换到另一个视图控制器? - How to switch to another view controller if some value in a table row is updated? 具有到另一个视图控制器的tableview的ViewController - ViewController with a tableview to another view controller 在应用程序启动结束时的root视图控制器,默认为cocos2d viewcontroller而不是另一个Storyboard视图 - root view controller at the end of application launch, defaulting to cocos2d viewcontroller instead of another storyboard view 如何使从视图控制器接收的字符串显示在另一个ViewController的表视图中 - How to make a string received from a view controller show up in a table view in another viewcontroller 如何将新的viewController推送到另一个视图控制器中的现有视图? - How can I push a new viewController into an existing view within another view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM