In the interface builder I have a UITabBarController
and it is set as the initial view controller. From the tab bar controller, I have linked three independent ViewControllers; two UIViewController
's and one UITableViewController
. I have embedded all three of these views inside UINavigationController
's as each of these views will eventually segue to a new view.
Problem:
I now want to link one of the UIViewController
's to the UITableViewController
using a button to segue to the table view. This way I can pass information, i.e. func prepareForSegue()
, to the table view. I want to maintain the tab bar controller at the bottom, however I do not want to have the ability to go back to the previous UIViewController
from the current UITableViewController
via a UIBarButtonItem
at the the top of the view; That is what the tab bar at the bottom is for.
However every time I segue "Show" the table view (it is actually a segue to the table views navigation controller), the navigation bars at the top and the bottom of the table view disappear. Is there anyway to prevent this from happening?
I have also tried segue "Show" directly to the table view, in which case the tab bar is visible, but then it displays a "back" button at the top of the view to segue back to the sending UIViewController
. I am hesitant about accepting a solution that would just hide the back button, because I feel I will run into problems down the road when I want to navigate to a detail view from the table view itself, since I would be bypassing the UITableViewController
's UINavigationController
.
Any solutions would be greatly appreciated. I have been trying to solve this problem for hours and I'm about to put my head through my computer screen. Also I thought about just using tabBarController?.selectedIndex
on the button click to shift to the table view, and then passing the information using NSUserDefaults
, but this is out of the question since I would be passing a custom object, and would have to encode and decode every custom field.
I you use a segue to get to it, as you say, you will still be using the
UIViewController
'sUINavigationController
which seems a bit messy. So I actually thinkselectedIndex
is probably the best way to go as once you change to theUITableViewController
you'll be in the correct navigation stack.Instead of using
NSUserDefaults
, why not just reference theUITableView
itself from theUIViewController
, set the values you want, and then swap to it usingself.tabBarController.selectedIndex
.So for your scenario above it, assuming the
UITableViewContollrer
is the third view in theUITabBarController
, you would do something like the following:Pass whatever you want into the
UITabBarController
by setting some pre-definedvar
in it. For example, if there was aString
calledsaveMe
in theUITableViewController
, then do the following in theUIViewController
:Swap to the
UITableViewController
using:The only issue with this is using
selectedIndex
won't perform a transition animation but not sure if you need this. This link could help if you do.