简体   繁体   中英

Two in one view controller

In android I can have one Activity with a fragment layout. And then I can swap layouts inside the fragment. How might I accomplish the same effect in iOS?

Here is what I tried but got stuck along the way:

  • In the parent ViewController p1 I add a ContainerView as a holder for the views to be swapped. (Note that p1 has other children views; not just the ContainerView)
  • But of course a ViewController c1 is auto-generated for (going inside) the ContainverView.
  • so I was thinking that c1 should be an abstract ViewController with two children ViewControllers v1 and v2 .
  • so at this point I am trying to create segues from c1 to v1 and then from c1 to v2 . But I cannot create the segue: xCode won't let me. I try to restart Xcode but that didn't help. So is there a problem with Xcode or is what I am trying to do not allowed?

For a bit more details

p1 has two buttons in addition to the ContainerView. If buttonOne is clicked I want the ContainerView to show, say, a horizontal TableView of ImageViews; but if buttonTwo is clicked then I want the ContainerView to show a vertical TableView of some custom TableView Cells.

In android I can accomplish this very simply by using two fragments: ImagesFragment, OtherDataFragment. Then I was swap the content of the fragment tag and voila!

I suggest looking at this example of a vertical tab bar controller. It shows how to create a custom segue to swap out the contents of a container view.

Creating a Custom Side Tab Bar using Storyboards and Custom Segues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM