Call master view controller from within detail view of split view controller - ios

I have a tab bar controller with 3 tabs, each embedded within its own navigation controller. This works great, but now I’m trying to put the entire tab bar controller within a split view controller.
The problem is the navigation on the master view for the split view controllers hides the existing navigation for the views inside the tab bar controller. If I hide the master view navigation, I get my tab bar controller navigation back but then I have no way of getting back to the master list. I can add the button back in programmatically but it only works on the iPad.
navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
navigationItem.leftItemsSupplementBackButton = true
I also tried playing around with the various options for preferredDisplayMode, but again, this only works on the iPad. It has no effect on the iPhone. I can add in a custom button programmatically to the view controller within the tab view controller and call an action from there, but I don't know what action to call. I tried calling the action on the displayModeButtonItem:
splitViewController?.displayModeButtonItem().action
That didn't work either. I would like to be able to just programmatically add back in the behavior of the back button that the split view controller adds on the iPhone.

I ended up scrapping the split view controller and just using anther tab. However I had a similar problem in another app and I figured out a kind of hacky solution. I embedded the tab bar controller itself inside a navigation controller. This causes multiple navigation controllers to appear so I did a check in viewWillAppear to hide whichever navigation controller is causing the issue.
if let hidden = tabBarController?.navigationController?.navigationBarHidden {
if hidden == true {
tabBarController?.navigationController?.navigationBarHidden = false
}
}
This app has a split view controller as the root view controller and then tab bar controllers in both the master and detail views. Every view is embedded in a navigation controller and I just show or hide the navigation bar depending on if I have a duplicate.

Related

Change View Controller in Tab Bar Controller (Swift)

A little background: My app pops a View Controller that has questions. When the person has answered the question, they swipe and View Controller is presented again, this time with new questions (so it is View Controller with question set 1 -> swipe -> (same) View Controller with question set 2).
This works fine when I do not have View Controller embedded in a Tab Bar Controller. However, when it is embedded in a Tab Bar Controller and I swipe, the View Controller is presented but the Tab Bar Controller is no longer there.
I want the tab bar to remain at the bottom of the screen but I want the View Controller to change upon swiping
func swipeGesture() {
// gesture stuff in here
self.present(ViewController(), animated: true)
}
In Tabbar Controller put a navigation controller. Above the same you can push as much as view controllers of same type or that of different types.
It will work.

How to segue to a specific view controller inside a tab bar controller with losing the tab bar?

Currently I have a tab bar controller that is connected to various navigation controllers like this:
I'm trying to navigate from one view controller to another view controller that is in a separate navigation controller. The only way I've been able to figure out how to keep the tab bar from disappearing is to create a modal segue to the original tab bar controller. The only problem doing this it automatically goes to the default tab bar viewcontroller and not the one I'm trying to reach.

Pushing view controller onto view control in tab controller

So I have a tab bar controller that holds a search view and a profile view. When I click on one of the cells in the search view I want to go to another view controller, still have my tab s on the bottom and maintain the user's ability to click a back button to go back to the main view.
I've achieved the back button part, but I haven't achieved the maintaing tabs part.
This is what I've tried -
-(void)displayCardController{
if(self.userProfile == nil){
[self.tabBarController setViewControllers:#[self.searchViewController, self.loginViewController]];
[self.searchViewController.navigationController pushViewController:self.searchViewController.detailController animated:YES];
} else {
[self.tabBarController setViewControllers:#[self.searchViewController, self.profileViewController]];
[self.searchViewController.navigationController pushViewController:self.searchViewController.detailController animated:YES];
}
}
The idea is - set the tab to have my controllers, and then push what I want to be on top. That doesn't work.
How do I achieve this?
It looks like the problem is that your first tab controller child, self.searchViewController, has a navigation controller. If you want to be able to push onto this controller while still staying inside the tab controller, you need the search view controller (or whatever is the first tab controller child) to be a navigation controller.
Note that its navigation bar can be hidden, so it won't look like a navigation controller, but when you push, you can show the nav bar and so give the user a clear way to get back.
Alternatively, use a different interface. What I do, for example, when I have two tabs and one of them needs to change temporarily, on the iPhone, is use a presented view controller: instead of push/pop, I use use present/dismiss. On the iPhone, this hides the tab bar, but we return to the same place when we're done so the interface is clear. (On the iPad, a presented view inside a tab bar controller does not have to hide the tab bar.)

Issue with tab and navigation view controller

I have an iOS app which is structured in this way:
One tab bar controller with 4 navigation controllers. Each navigation controller has its own view controller with a xib file.
The issue, is that ONLY THE FIRST TIME, when I push a new view into one of the navigation controllers, the new view doesn't appear at all. When I switch to another nav controller (touching one of tab bar's options) and then switch back to the first one, it works all the time.
The error I'm getting is when I come back is:
[35731:70b] Unbalanced calls to begin/end appearance transitions for
.
Thanks for helping out.
Make sure you are presenting all your view controllers from the parent / top level view controller (the tab bar controller). I've had this a few times when presenting a view controller from one of the view controllers in the tab bar.
In viewdidload assign your first view controller to load when xib loads. Its the correct way to load first view controller to appear when nib loads.

Create a TabBar Controller with a Master-detail template?

I created master-detail template for the ipad application and now I want to add Tab Bar to either master view or detail view. I can easily add tab bar controller using editor->embed in ->tab bar controller. However when I run application tab bar is not showing.
Tab bar is showing in storyboard but I am also unable to add extra tab bar items. What am I doing wrong thanks?
You should embed the navigation controller (of either the master or detail VC) in a tab bar controller, then delete the connection between the split view controller and that navigation controller. Finally, remake the connection from the split view controller to the tab bar controller. You'll also need to make several code changes, because the template code refers to the detail controller by its hierarchy in the split view controller, which will now be different.

Resources