3

I am using a ContainerView to share a view amongst the various ViewControllers in an iOS app. This works well for the most part, except for the TabViewController, where it causes an extra blank tab item to be created. I have attached a screenshot from the storyboard, where you can see 4 Relationship listings and 1 Embed Segue listing in the document outline. As best that I can tell, the Embed Segue connection for the TabViewController is being parsed (/confused) as a 5th Relationship connection and thus a tab item. Considering that the Relationship & Embed Segue connections in the storyboard look similar (apart from a slightly different icon) and that they appear listed next to each other in the document outline, I can see how this bug could occur.

In an effort to compensate for the bug, I used the tabItem titlePositionAdjustment to center the 4 legit tabs in the interface. The problem here is that I am only able to compensate for the tab icons / labels, but not the actual buttons, themselves. The 5 tab bar controller buttons seemed to be at a fixed position, regardless.

I am hoping that someone else out there has run into this issue and can offer a solution or a better way to mitigate the issue.

Thank You!

enter image description here

enter image description here

vfxdrummer
  • 436
  • 4
  • 7
  • Can you explain more of why you need the Container View, and how you use it? I suspect it will be easier to find another solution for that. – pbasdf Feb 05 '17 at 09:36
  • Yes, of course. So, the product is a music app. (Earbits Music Discovery on App Store). We have a small mini player that we want to be visible as a subview on all screens. I did some research on how best to share a view with multiple view controllers and container view is what I arrived at. Here is one of the tutorials that I followed : https://spin.atomicobject.com/2015/07/21/ios-container-views/ – vfxdrummer Feb 05 '17 at 21:13
  • 2
    Thanks. Could you add the container view to the home, browse, playlist, etc view controller when their tab is selected? – pbasdf Feb 05 '17 at 21:32
  • Yes, I can definitely try that. I will give it a shot in the morning and let you know. Thanks. – vfxdrummer Feb 06 '17 at 06:01
  • Yes, this seems to work. Hooked it up to one tab, let me do the others. Thank you for the suggestion. Seems very obvious, in retrospect. Give me a sec. to finish the others. – vfxdrummer Feb 06 '17 at 18:10
  • This works! Thanks so much. – vfxdrummer Feb 06 '17 at 18:34
  • How do I accept this as the answer? – vfxdrummer Feb 06 '17 at 18:36
  • Ok, this works, but it doesn't stay pinned to the tabViewController. I suspect that I can just add another view that the containerView is pinned to, and put the tableViews inside of that. – vfxdrummer Feb 06 '17 at 18:41
  • Sounds like there are some subtleties I didn't consider. Might be best if you add an answer to your own question (that's perfectly valid), since you are resolving the details. – pbasdf Feb 06 '17 at 18:44
  • Sounds good, thanks. – vfxdrummer Feb 06 '17 at 21:35
  • Good news. It looks like I can just create one viewContainer in the first view controller, attach it to a subview of the tabBar, and it works for all of them. – vfxdrummer Feb 07 '17 at 00:57

1 Answers1

1

Ok -

pbasdf sent me in the right direction. In the end, I added a viewContainer to each of the 4 views connected to my tabView, w/ an EmbedSegue to the shared View.

The catch is that you only need one of those view controllers to attach the viewContainer as a subView of the tabViewController. Then, it gets shared with all the view controllers in the tabViewController.

So, I have both a working tabViewController with 4 buttons positioned properly by default, along with an embedded containerView above it.

vfxdrummer
  • 436
  • 4
  • 7
  • Just an update. My fix for this didn't end up working out. Because the view that I add as a subview of the TabView belongs to one of its view controller, it violates a proper view hierarchy. It cause the following exception : UIViewControlHierarchyInconsistency. So, I still don't know of a way to use container views in a Tab View Controller properly. – vfxdrummer Feb 17 '17 at 21:43