Performing Modal and Push Segue From Tab bar Item press - ios

A little background that I think will help in this question:
I am working on an iOS7 app which basically presents various quotes and allows the user to share these quotes through facebook or twitter. I am implementing this through a tab bar (not a tab bar controller) that I placed at the bottom of the first view controller in the screenshot.
The tab bar's delegate (file owner) is set to be the view controller that it's in. In there I edited the tabbar: didSelectItem: method to handle every button press accordingly. (The first two button presses are just modal segues to twitter and facebook tools.)
Now my question:
Now I am trying to get the third item in the tab bar to cause a segue to the third view controller (upper right). Can I make a tab bar item perform a push segue? How would I go about doing that?
I have been trying to look for a way to do this but seemed to be stumped. I was thinking that maybe this can be done with a tab bar view controller but then I wasn't sure how I could have my original first two tab bar items perform modal segues
Any help would be appreciated
UPDATE:
The two view controllers at the bottom are segued into when the user touches either of the two views in the first view controller (can be ignored for this queston). The third VC (in the top right) I want to be pushed when the user touches the third tab bar item. The bottom two views just display info about quote presented... the top right vc allows the user to enter a new quote and save it.

You only need to connect a segue from the controller with the tab bar to the third controller, and call it manually in the didSelectItem method,
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if ([item.title isEqualToString:#"Third"]) { // or whatever your title is
[self performSegueWithIdentifier:#"GoToThird" sender:self];
}

Related

Add Main Tab Bar to Other View Controller

I'm a new Swift developer. I'm using Swift 4.2 and XCode 10.2.
I have a tab bar controller with 5 tab bar items. In the view controller for each tab bar item there is a button to show the balance in a different view controller (call it the Balance View Controller). I have a segue from each button to the Balance View Controller.
I am using interface builder, but will be happy to add code.
How can I put the main tab bar on the Balance View Controller so when the user is done viewing the balance, he can select another tab bar item and keep going? I rejected using a navigation controller because the back button will interfere with the uniform view at the top of every screen and I don't want to adjust it.
I could not find any SO questions that address this issue. And all the other web resources I found are very basic on how to implement tab bars. Any help would be appreciated.
Another approach:
Load Balance View Controller as a Child ViewController, and display its view on top of the current view. This will leave the tab bar alone, allowing users to navigate to another tab.
Balance View Controller sounds like it's just an information display. If so, you can add a tap gesture to remove it from the current view on a simple tap.
If Balance View Controller is interactive, you can add a button to remove it from the current view.
Since you say you have a button in each tab's VC to show the Balance View Controller, then you probably also want to remove it from the current view when another tab is selected.
I rejected using a navigation controller because the back button will interfere with the uniform view at the top of every screen and I don't want to adjust it.
The best way to achieve this is with a UINavigationController what we can do about the Top navigation bar and the darn back button is we can hide the whole thing by
// Add this to your viewcontroller
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
}
And going further if you want to you can disable the animations for the view controller
hope this helps

Losing #IBOutlets after Segue

I'm working with the Xcode view editor and Swift.
I have my main view which contains a tab bar controller with 2 tabs.
On the second tab, I have a #IBoutlet var myLabel: UITextLabel!. Inside viewWillAppear I put some text in this label.
On the first tab, I have a button which launch a third view through a Push segue, and on this new tab, I have a Back button which gets me back to the main view containing a tab bar controller (through a push segue too).
When I launch my app, go in my second tab, the text of the UITextLabel is changed.
I still can go to my first tab and navigate between them it works.
But the problem is when I click on my first tab's button, then on Cancel, then goes back to my second tab, my UITextLabel doesn't change. And I can't perform any action on it anymore. It's not nil though but it's like it's still connected to the first UITextLabel before the segue and not this one.
Where am I wrong ?
Several things are wrong.
With tabbed apps, Apple says that the tab bar controller should be the root level navigation method for the app. It should always be present, and the user should always be able to tap another tap to switch to another part of the app.
So the first tab should connect to a navigation controller. When the user pushes the button, you should push a new view controller onto that navigation controller. The tab bar will still be visible and enabled, and the user will still be able to switch to view controller one.
Next thing:
You say "I have a Back button which gets me back to the main view containing a tab bar controller (through a push segue too)."
That's very wrong. Back buttons should pop a view off of the current navigation stack. They should not be pushing anything. Any time you use a push segue, you are creating and pushing a brand new instance of a view controller, and leaving the other view controllers in the navigation stack.

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.)

How to create a UIView with NavigationBar and TabBar

I would like to introduce in my app a View that will contains both navigation bar and a tab bar at the bottom. View contains a Table View with multiple entries and once user tap on a cell a push segue takes him to another view with details regarding the cell he has previously tapped. If he decides, user can go back to parent view by tapping on 'Back' button of the navigation bar on top. In addition to this, I would like my view to have a tab bar at the bottom with extra tools for the user. So, if he decides to check the 'Creator' of the app, he can by simply tap on 'Creator' TabBarItem at the bottom.
I would like to ask you what is the best way to achieve the above. I have already tried to use UITabBarController combined with UINavigationController. Didn't achieve what I was looking for because I would like the view with the table on it to be independent from the TabBarController and NOT a part of it (by part I mean by accessible through tabs).
Do you believe a UINavigationController view with UITabBarView would be a better choice?
UPDATE
What I mean by, "independent from the TabBarController and NOT a part of it":
Once the app loaded, I would like to see my main view (with table) contains Navigation Bar on top and Tab Bar at the bottom. However, I don't want to see the first tab of the Tab Bar selected because my main view will not be accessible through tabs of the Tab Bar but through Navigation Bar. If, for example, I am in Main view and tap on 1st tap, I would like to move to another view that will contains some other info.
Option 1:-
Create a tab bar Controller and on that TabbarController assign your navigation Views.
say nav1 with tab1 , nav2 with tab2...
Option 2:-
Create a Navigation View Controller and than add the tabbarcontroller on that navigationView Controller by using addSubView.
So when the user clicks on a row in a table u will go to a different View which doesn't have the TabbarController and when the user comes back he will again see the TabbarController.
This is what I will do:
First I will subclass UITabbarController and create for example ParentTabBarController. This controller will contain all the tabs necessary and what they will do if they are clicked so on.
Next for each viewcontroller I create, I will subclass from this ParentTabBarController so that the tabs are already in. You can add additional functionality or override it depending on your situation.
In your appdelegate pass in a navigation controller and every time push and dismiss the viewcontrollers you created in second step.
Hope this helps..

Tab bar disappears when trying to go back from new view

I am very new to Xcode and have encountered an issue with my app. I am trying to create a tab bar app. On one of the tabs I have a button that brings the user to a different ViewController. I want to have it so the user can select a button that would return them to the tab that had the button. I tried to set up an action from the button to the previous view (the tabbed screen), however the tab bar disappears. I hope this is makes sense.
Here is a link to a screenshot...
Easiest way to do this is to place a UINavigationController as the root view controller of the TabBarController. You can do this in storyboard by simply ctrl+dragging from the tabbar controller to the navigation controller and adding it as a relationship.
Here's an example using storyboards:
The next step is to set the third controller (in this case the table view controller) to your player view controller class.
Then, you can use the default back button and animation that comes with the navigation controller. If you prefer to hide the navigation bar at the top of the screen, then you can use your custom back button to call
[self.navigationController popViewControllerAnimated:YES];
You can also choose custom animations / segues, etc. but using a navigation controller to help you navigate screens is probably the simplest approach.

Resources