更改 UISplitViewController 上详细信息窗格的视图
我正在开发一个应用程序,尝试更多地了解 cocoa touch 框架,并开始使用 UISplitViewController
。据我目前所知,它有一个名为 viewControllers 的属性,它是一个包含应用程序的主视图控制器和详细视图控制器的数组。
我试图在masterVC
中设置一个文件夹导航系统,然后当选择特定文件时,它会在detailVC
中打开。我已经使文件夹导航正常工作,并且可以在两个视图控制器之间传递文件的详细信息。
我的问题是有多种类型的文件需要不同的视图才能正确显示。
例如,jpeg 图像将有一个图像查看器,而 html 文档将有一个 Web 视图,而 txt 文档将需要一个文本编辑器视图。
更改详细信息窗格的视图控制器的最佳方法是什么?
我是否最好拥有一个视图控制器并根据文件类型交换不同的视图?或者有没有一种方法可以完全删除视图控制器并在其位置添加适当的视图控制器?
谢谢
I am working on an app to try and learn a bit more about the cocoa touch framework and am starting to use the UISplitViewController
. From what I have learned so far, this has a property called viewControllers
that is an array containing the master and detail view controllers for the app.
What I am trying to set up is a folder navigation system in the masterVC
, then when a specific file is selected, it is opened in the detailVC
. I have got the folder navigation working and can pass the details of the files between the two view controllers.
My problem is that there are several types of files that require different views to display them correctly.
For example a jpeg image will have an image viewer, whereas an html document will have a web view and a txt document will require a text editor view.
What is the best way to change the view controller of the detail pane?
Am I better to have a single View controller and swap different views in and out depending on the file type? Or is there a way to completely remove the viewcontroller and add the appropriate one in its place?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该使用多个视图控制器。您提到的每个单独的视图控制器中必然有很多逻辑,这些逻辑应该正确包含在其自己的视图控制器中。
至于显示适当的视图控制器,您可以轻松地将
UIViewController
的view
添加到任何UIViewController
的视图,方法是: [self.view addSubview:myTextEditorVC.view]。换句话说,您的detailVC
可以处理了解需要显示哪种类型的UIViewController
的逻辑,实例化该UIViewController
并显示其detailVC
的view
内的view
。希望这有帮助!
I would think you should use multiple view controllers. There's bound to be a lot of logic in each of these individual view controllers you mentioned that should be properly contained within its own view controller.
As for displaying the appropriate view controller, you can easily add a
view
of aUIViewController
to anyUIViewController
s view, by doing:[self.view addSubview:myTextEditorVC.view]
. So in other words, yourdetailVC
could handle the logic of knowing which type ofUIViewController
it needs to display, instantiate thatUIViewController
, and display itsview
within thedetailVC
'sview
.Hope this helps!
您应该更换不同的视图控制器。在 Xcode 6 中,您可以使用主控中的“显示详细信息”segue 来指向包含不同详细信息视图的不同导航控制器。
这是一个简单的示例。
You should be swapping out different view controllers. In Xcode 6, you can use a "Show Detail" segue from the master to point to a different navigation controller that contains your different detail view.
Here's an quick example.