4

(I have read other questions and answers on this topic, but most are very old and do not relate to iOS 9 or 10.)

The app design calls for the top half of the display to always contain the same content. (An image being edited by the user.)

The bottom half of the display needs a UITableView. When a UITableViewCell is tapped, the bottom section needs to transition to a new UIViewController with slide-on animation, similar to how UINavigationController push segues work.

Problem: only the bottom view needs to transition to the new view controller(s), and back again. The upper half of the view hierarchy needs to remain unaffected. For this reason, I can't place everything inside a UINavigationController, and I can't have a UINavigationBar at the top of the screen.

Question: what approach should I take in such a situation, where I need only one UIView hierarchy to transition in push-segue fashion, but not anything else? Thanks.

Edited with Solution

Solution follows, for those following along at home.

Storyboard layout

Result

Push Segue

Womble
  • 4,607
  • 2
  • 31
  • 45
  • are you trying to do this all in a storyboard? this would be simpler if written in code. you could just animate the views' frames from right-left or left-right – Hayden Holligan Aug 03 '16 at 05:25
  • How did you get this to look like the above picture? I am trying to build a NavigationController (which contains a multi-level UITableView) into a UIViewController that has a static area on top and bottom. IB is not showing me a "container view" but only a UIView. – Trygve May 13 '20 at 18:42

3 Answers3

4

Yes, you can actually use a UINavigationController for the bottom half.

If you are using Storyboards, the easiest way to do this is to use a container view for each part of the screen which you then can embed a UIViewController in for the top part and a UINavigationController in for the bottom part. If you are doing this programmatically, just add the view controllers as child view controllers to your app's initial view controller (see this answer for more info) which is essentially what the Storyboard will do for you automatically when using a container view.

As a child view controller, the UINavigationController will act independently from the top UIViewController and should behave as expected.

I recommend the programatic approach for the following reasons:

  • It helps you understand the inner workings of child/parent view controllers much better which will likely save you a significant amount of debugging time down the line.
  • It makes adding/removing/swapping child view controllers as simple as a few lines of code. Trying to do this with Storyboards is notoriously hacky and cumbersome.
  • It's much easier to keep track of changes using GIT (most mid-size/larger companies actually prohibit Storyboards for this very reason)
Community
  • 1
  • 1
William LeGate
  • 540
  • 7
  • 18
  • 1
    Thank you so much, and thank you to the other respondents too! Following your advice, I have manage to get the design working by using two container views, with a UINavigationController in the second container, embedding the UI I need. Big cheers! – Womble Aug 04 '16 at 02:59
  • I'll also explore your suggestion about working in code more, rather than using Storyboards. Cheers. – Womble Aug 04 '16 at 03:14
1

If you want change in part of the screen you can use container view. For details refer Swift - How to link two view controllers into one container view and switch between them using segmented control?

Community
  • 1
  • 1
1

You can use multiple view in one view controller and can give animation like push or pop to show or hide it.

Second approach is you can use Container View which will give exact effect like navigation stack.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75