开发者

Change view of detail pane on UISplitViewController

开发者 https://www.devze.com 2023-02-04 17:42 出处:网络
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 viewCon

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开发者_如何学C 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


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号