更改 UISplitViewController 上详细信息窗格的视图

发布于 2024-10-12 18:49:31 字数 494 浏览 4 评论 0原文

我正在开发一个应用程序,尝试更多地了解 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 技术交流群。

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

发布评论

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

评论(2

疾风者 2024-10-19 18:49:31

我认为你应该使用多个视图控制器。您提到的每个单独的视图控制器中必然有很多逻辑,这些逻辑应该正确包含在其自己的视图控制器中。

至于显示适当的视图控制器,您可以轻松地将 UIViewControllerview 添加到任何 UIViewController 的视图,方法是: [self.view addSubview:myTextEditorVC.view]。换句话说,您的 detailVC 可以处理了解需要显示哪种类型的 UIViewController 的逻辑,实例化该 UIViewController 并显示其detailVCview 内的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 a UIViewController to any UIViewControllers view, by doing: [self.view addSubview:myTextEditorVC.view]. So in other words, your detailVC could handle the logic of knowing which type of UIViewController it needs to display, instantiate that UIViewController, and display its view within the detailVC's view.

Hope this helps!

堇色安年 2024-10-19 18:49:31

您应该更换不同的视图控制器。在 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.

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