I am presenting a modal view controller off of one my tabs in ios7. Depending on the user's action, I want to change the selected index of the tab bar controller.
I have tried
[(UITabBarController *)self.parentViewController setSelectedIndex:0];
This does not change the selectedindex of the underlying tab bar. Please let me knwo if there is another way to do this
Just do
UITabBarController *tabBarController = (UITabBarController *)self.presentingViewController;
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
[tabBarController setSelectedIndex:1];
Related
I have seen this topic (iOS Storyboard Back Button) and more about this subject, but I still cannot have my back button appear on screen :
I have got 2 viewControllers, the two of them have a navigationController, the "father" controller has the button bar item set to "back" as a plain text, the second viewController appear well with a modal segue, or with "show detail (replace)" segue, but nothing appear on the navigation bar to come back... Would you know why?
Here is a capture :
Thanks
EDIT :
with a custom transition, and when presenting the controller via the navigator in the code, the back button is not here anymore... would someone know why?
When I comment out presentViewController:secondViewController, the back button is here, but the custom animation is not triggered anymore, there is the normal transition set in the storyboard.
Here is my method :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(#"segue descr %# : ", [[sender class] description] );
if ( [[segue identifier] isEqualToString:#"second"] ){
//SecondViewController *secondViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"SecondViewController"];
SecondViewController *secondViewController = [segue destinationViewController];
secondViewController.transitioningDelegate = self;
[self.navigationController presentViewController:secondViewController
animated:YES
completion:nil];
Modal and show detail segues don't use a back button, because they are like independent views.
The idea is that those those views are only showing extra information or details about something and you can close them programmatically when you need to go back to the previous view.
A show or push segue will give you the back button in your navigation controller, because that segue is meant to be more like a sequence of views.
When you push a View Controller, you get the back button for "free" without having to write extra code. When you present a modal View Controller, you need to add your own way of dismissing the modal view. Since you have a Navigation Controller, your easiest route is probably to add a UIBarButtonItem to the navigation bar, and have that bar button call dismissViewControllerAnimated:completion: in your UIViewController subclass.
I want a transparent black theme throughout my iOS app on both navigation bars, tab bars, and toolbars (I use all 3), and I have this set up through storyboards. I have a subclassed tabbar controller that presents a sign up modal with a navigation controller programmatically as follows:
UserSignUpViewController *userSignUpViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"UserSignUpViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:userSignUpViewController];
userSignUpViewController.delegate = self;
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
this is called in my subclass tabbars view did appear, so I can see that my tabbar shows up as translucent black before this animates up modally. when I dismiss this sign up navigation controller, the tabbar reverts to "opaque" meaning solid white. Why is this happening and how do I fix it?
The tab/navigation bar tint colors that I set in my appdelegate persist but the translucent styling of the bars gets reset for some reason. I should add that if I don't display the sign up view controller (user is already signed in), then the tab bar is the correct styling. Thanks!
It could be because you are calling it in viewDidAppear instead of viewDidLoad
I am trying to create a tabview project with three tabs (A,B,C). Tabs A and C are tableview controllers which work well. Tab B I want to make a ViewController that will use the camera using a AVCaptureSession. The question I have is how do I make Tab B display the camera modally over the tabview?
You could just present any modal controller without animation in viewDidLoad or viewWillAppear.
UIViewController *vc = [[UIViewController alloc] init];
vc.view.frame = [[UIScreen mainScreen] bounds];
vc.view.backgroundColor = [UIColor purpleColor]; // for testing
[self presentViewController:vc animated:NO completion:nil];
In that view controller you can do whatever you like, including starting a AVCaptureSession.
In order to return to the previously selected tab controller there are several options.
One is to switch to the desired tab when dismissing the modal view controller. Suppose it has a property or ivar called lastTab:
self.tabBarController.selectedViewController
= [self.tabBarController.viewControllers objectAtIndex:lastTab];
Another way is to never actually activate the tab with the modal view but launch the modal view controller directly from the other tabs. The other view controller could set the selected tab back to itself and then launch the modal view.
i have created a tab bar application,
There is a present modal view controller when button clicked in viewcontroller 1, and with navigation controller i can navigate to Viewcontroller2 from modal view
My problem is that,when i navigated to viewController2 the tab bar is hidden,how can i show the tab bar?
If you're pushing a view controller onto your navigation controller's stack, then the tab bar will stay:
[self.navigationController pushViewController:viewController2 animated:YES];
But if you're presenting it as a modal view controller then it becomes the top/front-most view (presented in full screen), thus hiding the tab bar until the view controller is dismissed:
[self presentViewController:viewController2 animated:YES completion:nil];
The point of a modal view controller is to force the user to deal with the presented view controller before doing anything else inside the app. If you need to access viewController1 in viewController2 then you could declare a property viewController1 *previousViewController in viewController2 and set viewController2.previousViewController = self; (in viewController1) before presenting the view controller. Alternatively you could try adding the view (subtracting the height of the tab bar when defining the frame) to your tab bar controller's view.
I'm pushing a number of views:
the top one is a UITabBarController
the second one is a UINavigationController with a pushed view
the third one is a modal box.
Once the close button in the modalbox is pressed I'm trying to revert everything to the default state and change the tabbar index.
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:NO];
[self.tabBarController setSelectedIndex:3];
This dismisses the modal view but doesn't do anything else. Any ideas what could be wrong? I read something about a possible ios bug but I don't know how to work around it.
Neither UITabBarController nor UINavigationController is a view. Both are subclasses of UIViewController and have a property NSArray *viewControllers.
If you have an actualView controlled by an ActualViewController that is pushed on top of a rootView controlled by a RootViewController that is the rootViewController for the navigationController, and you also have a modalView controlled by a ModalViewController, then put
[self dismissModalViewControllerAnimated:YES];
in ModalViewController.m, and put
[self.navigationController popViewControllerAnimated:NO];
in ActualViewController.m (from whence modalView is pushed, presumably), and put
[self.tabBarController setSelectedIndex:3];
in RootViewController.m (from whence actualView is pushed, presumably).
If modalViewController was never added to the navigationController, then it doesn't know that the navigationController exists.
If actualViewController was never added to the tabBarController, then it doesn't know that the tabBarController exists.
The easy (and dirty) way:
Dismiss the modal view in the modal view. Make the navigation view controller the delegate of the modal view. Make the tabbar controller the delegate of the navigation controller. When the button is pressed call a method in the navigation controller that pops the view and calls a method of the tabbar controller which changes the selected tab.