I have a UITabBarController With the 2 Tabs. I want When I click on the Tab 2 (viewController B) then click on the Next button with navigationcontroller (viewController C). Then, I click Back button (custom button) to come back to Tab 1 (ViewController A) and I want when again I come back to Tab 2 the view controller should be display viewController B.
Thanks !
On the custom button (Back button) action you should call popViewController and then jump to Tab 1. or when pressing on the Tab 2 you can check if you are in the root view controller of the navigationcontroller and if not put ViewController B as the root.
Related
I have created a Tab Bar Controller in Swift, but the Tab Bar Item will not show up. The tab bar view controller is being opened from another view controller via a segue between the other view controller (not a UIButton, but directly from the view controller) and the tab bar view controller. I feel like this has something to do with it, but I am not sure. Here is an image of my storyboard in Xcode:
You need Two Segues Here From Your Very First Screen
Segue 1 : Navigate to Get Start Screen Where submit Button is connected on click of Get Started Button
Segue 2 : Navigate to TabBarController Directly on click of Go Directly Button
Segues From GetStarted Screen
Segue 1 : Navigate to Tab Bar Controller on click of Submit Button
Note
-> You had Connected a Segue From veryFirst Screen to GetStarted Screen Thats Correct
-> From GetStarted Screen you had connected a Segue to First TabBar Screen instead of TabBar controller
Expected Output
Navigate through Get Started Screen
Navigate Directly
Hello Im trying to segue from a modal to a tab bar view controller without losing the tab bar? I know the question is short, but this is all I'm asking.
Scenario: I have a Tab Bar View Controllers, A and B. B modals to C view controller. Then I want to return to View Controller A.
Swift please :D
Here is my example of how to do this. In my setup, I choose the yellow ViewController from the tab, then press Go! which modally presents the white ViewController. Pressing Exit returns to the green ViewController.
To set this up, use an unwind segue to return to the viewController that called you. For instance, implement this in the first ViewController of the tab (the one calling the modal segue).
#IBAction func backFromModal(_ segue: UIStoryboardSegue) {
print("and we are back")
// Switch to the second tab (tabs are numbered 0, 1, 2)
self.tabBarController?.selectedIndex = 1
}
Then switch to another tab using self.tabBarController?.selectedIndex = n where n is the number of the tab you really want to go to. To set up the unwind segue, you can either control-drag from a button in your modal view controller to the exit icon at the top of the viewController and select backFromModal from the pop up...
OR
you can set up the unwind segue to be called programmatically by control-dragging from the viewController icon at the top of the modal viewController to the exit icon, and select backFromModal from the pop up.
Then, go to the Document Outline View and click on the unwind segue
and give it an identifier in the Attributes Inspector on the right (for example "returnFromModal").
Then you'd call the unwind segue like this:
self.performSegue(withIdentifier: "returnFromModal", sender: self)
I have created a tabbar based application which contains, let say, 3 tabs. In my first tab, I have 3 UIButtons. on clicking button 1, a new viewcontroller 1 is loaded and the tab 1 is highlighted as selected. On clicking button 2, a different view is loaded (Viewcontroller 2) and tab 2 should be highlighted as selected tab (Remember, this viewcontroller 2 is not the root view controller of tab 2) and on clicking button 3, again a new view is shown (viewcontroller 3) and tab 3 should be highlighted as selected (Remember, this viewcontroller 3 is not the root view controller of tab 3).
So, what I want to do is, I want a particular tab to be shown as selected (or highlighted), but dont want to load its root view controller.
I have tried using tabbarcontroller.selectedindex = 1 on clicking of button 1, but it went in vain. Because what happened was tab 1 got selected and the view being shown to me was not viewcontroller 2. Instead it was the root view controller of tab 2. Somebody pls get me out of this mess....
If that is indeed your requirement, the best way is to create a 'fake' tab bar using custom uiimageview. You will need three imageview and change the images accordingly as you tap the buttons.
I have following set up in the interface builder:
Files' Owner
First Responder
App Delegate
Window
-> Tab Bar Controller
Tab Bar
->Selected Navigation Controller (X)
Navigation Bar
->X View Controller (X Class)
Navigation Item
Tab Bar Item (X)
->Navigation Controller (Y)
Navigation Bar
->Y View Controller (Y Class)
Navigation Item
Tab Bar Item (Y)
X and Y tab bars have their own nib's.
In my app delegate, I add tab view controller to the main window view:
[window addSubview:tabController.view];
[window makeKeyAndVisible];
And all this works great. However, I now need to insert a view with two buttons. One button would take me to above explained tab controller view. The second button would take me to another subview (not yet implemented) which will only have an other action button in its view.
I should be able to navigate back to the main window (two buttons) from any of the subviews.
Is this possible? How to do it?
I don't know if this helps, but probably what you need here is a UINavigationController. With such a controller, put as the main view controller of the app, you can create the two buttons, and when the user touches one of them, you change the navigation controller display using its pushViewController:animated: method.
In this way you obtain the classic backwards arrow button item in the toolbar of the new view that will permit you to go back to the home page.
I have a root view controller as the navigation controller. In the root view controller nib file I have 3 buttons (button 1, button 2, button3). Each of which has a table view contoller Eg: Flow of the buttons (I have followed the navigation logic such that at any time I can get back to the root view controller by selecting the back button).
On Button 1 click => table view shown ==> detail view shown on item click/selection
On Button 2 click => table view shown ==> detail view shown on item click/selection
This logic holds good for all the buttons. In the detail view I have a button.
What I want is on the click of this button, the button 3 logic should be called such that, when i click or press the back button from the table view of 3rd button, I should get back to the main root view controller with all the buttons visible.
Please let me know how should i go ahead with the same.
I believe you'll want to use the - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated found in UINavigationController. As the name suggests, this will allow you to pop back to the root view controller at any time.