I want to use two different TabBarController. Everything is declared in my AppDelegate. Here is the result :
TBC1Tab1 | TBC1Tab2 | TBC1Tab3 and then when I push a button my new TabBarController : TBC2Tab1 | TBC2Tab2
Each Tab is linked to a view. I use a button on my first tab to go to my second TabBarController with my new tabs. My problem is to go back to my first TabBarController : how to do it ?
So to have my "back" button I add my code in my views. Then if I use my back button I can't go back to my first view from my first TabBarController.
Here is what happens : my view inside my second TabBarController (which is linked to my tab) disappear but my TabBarController doesn't disappear so I can't see my first view with my first TabBarController.
Someone know how to do it ? If you don't understand I will add some pictures. thanks
you need to use two methods in your app delegate
one will work by clicking on your button in tab bar and other will work by clicking on back button
make sure your back button should not be navigation controllers back bar button
that must be custom button
if u have any problem in putting your custom button in the place of back button
put it in right part
thats it other wise if u want to come back it wont work because
navigation controller is the child class of tab bar controller
in NSObject
so
if u want to try with custom button i think u know the answer
other wise call again previous method view did load in 2 nd button
Related
Attached are two images. The first shows my current main.storyboard, and the second shows my problem when I run the app. I have a tab bar controller that has two tabs. On the first tab there is a button. When pressed, the button goes to another view controller with content. At the top is a Navigation bar with a back button. After viewing content, I press the back button, and am back on the original page with the button, but the tab bar is missing. I have seen a few answered questions, but it appears they made their tab bar in the view controller instead of the storyboard. Another says that I should never return to a previous view unless I use an unwind segue. Is this true? If so, how do I set up an unwind segue. If not, how do I fix this problem otherwise? Thank you.
http://i.stack.imgur.com/IYmX2.png
http://i.stack.imgur.com/7slt5.png
The problem is in the wiring of your ViewControllers. You have probably embedded your UITabBarController inside the UINavigationController and not the other way around.
A correct layout looks like this in Interface Builder :
To reproduce:
In Interface Builder drop a UITabBarController. This will come with 2 UIViewController's already wired in.
Pick one of the UIViewController's (let's call it VController1) and click on Editor / Embed in / Navigation Controller. This wires the VController1 to live inside a UINavigationController that is inside the UITabBarController
Add a 3rd UIViewController next to VController1 Let's call it VController3
Wire in a segue between VController1 and VController3, for example with a button.
I hope that's clear enough
Try Linking the button in your viewcontroller (other than the views of the tabbed bar controller) with the tabbed bar controller. Create a segue that links the button with the controller of the tabbed bar application
I have two View Controllers, I need to have a button in ViewControllerOne that when I press it Show me ViewControllerTwo.
In storyboard I related both views with a "Presenting Segues" - Push modal. And both views have a view controller class.
I'm not sure what you mean by "I related both views with a 'Presenting Segues' - Push modal." Are you using a navigation controller and want a push segue, or do you want to do a modal segue? A "push modal" is a contradiction in terms.
So, let's imagine that you want a modal segue. So, you put a button on the first view, right-click and drag (or control-click and drag) from that button to the second view.
You'll get a pop up asking for type of segue. Select "modal".
And you're done transitioning from 1 to 2. No code necessary.
If you want a button on the second view to take you back to the first view, you do not want a modal segue from the second view back to the first view, but rather you want to dismissViewControllerAnimated. You can do this via a custom segue, or easier, just have a button which calls dismissViewControllerAnimated. Thus, you'd add a button to the second view, and while the editor is in in "assistant" mode (where the associated .h file is showing below the interface builder; see below if you want to know how to show the .h file at the same time as the Interface Builder screen), right-click (or control-click) and drag from the button on the second view down to the second view controller's .h file:
By the way, if you don't see the .h file there, click on the "assistant" editor button and choose "automatic" for the files to be shown down there, and you should be good:
It will then show you a pop up asking you what you want to do. Select IBAction and give your new method a name:
Then go to your code for the view controller, and add the dismissViewControllerAnimated code:
All that code says (and in this example, I just called my IBAction dismissTwo) is:
- (IBAction)dismissTwo:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
If you want to do a push segue, it's even easier. First, if you don't already have a navigation controller, add one by selecting the first view and choose "Embed in" - "Navigation Controller":
When you do this, you'll have a new navigation controller (which you don't really need to do much with) and the first view will have a navigation bar.
Now, right-click (or control-click) on your first view's button and drag over to the second view:
This time, select the "push" segue:
And you'll know that it worked, because your second view will have a navigation controller
You don't need a button to go back, because the navigation controller will automatically have a "Back" button, so you don't need to add your own.
This is how you achieve a push segue.
I have a root view controller with just a simple navigation button that loads a questionview. When I use pushViewController a back button appears. Instead I want a custom button in the top right of the uinavigationcontroller and I want to remove the back button after the page transition.
how can i achieve this..
Take a look at UINavigationItem. You can accomplish both your goals by properly configuring your view controller's navigation item. Use the -setHidesBackButton:animated: to hide the back button, and the -setRightBarButtonItem:animated: to add your custom button on the right side of the navigation bar.
I have a tabbar based app and would like to reference one of three views. There are three tabs. When tab2 is clicked, tab2view is created. tab1view needs to reference tab2view so it can be pushed into view. tab2view can be pushed into view via tab2 or tab1view. How do I give tab1view a reference to tab2view?
tab1view will also need to create tab2view if it hasn't already been created from a tab click.
You don't push views with UITabBarControllers, you add View Controllers to an array that get displayed when the user clicks the appropriate tab bar item. If by "push" you mean "switch to tab" then you just need to set the "selectedIndex" property of your TabBarController.
But I don't understand this dependency you have where the second tab's view controller has to be created by the first. If you're not seeing your second tab view when you click on the second tab button, then it means you're doing something wrong in building the tab bar itself.
Regardless, all view controllers in your tab bar are accessible via the "viewControllers" array so getting the second one would be:
UIViewController *secondVC = [[myTabBarController viewControllers] objectAtIndex:1];
I add 3 views for an application and they need to switch from 1-2-3.
Now I add a toolBar and a button 'OK' on the bottom of SwitchViewController, so they can share the button to go to next view.
But how to add a 'Back' button so that I can switch from 2-1 or 3-2 and the button shouldn't be seen in the first view?
Are there any other ways to switch views without sharing the same tool bar button?
It sounds like what you're trying to do is use a UINavigationController. If you instantiate a UINavigationController with the initWithRootViewController initializer you can pass it your first UIViewController. Then you just need to tie whatever action you want to a method that calls [myUINavigationController pushViewController:myOtherViewController animated:YES] to get it to slide over to the second view. The UINavigationController will automatically set up the UINavigationBar and back button you are looking for.