this is my problem.
I have a tab bar, in the last tab I load a modal view. When I dismiss the modal view the app returns in the last tab of the tab bar. But instead I'd like that the app returns on the first tab of the tab bar (the initial view).
if I dismiss the modal view the code that I insert after (to call initial view controller) is not taken in account. Can you offer me a solution? Thank you.
The code that I use is:
[self dismissViewControllerAnimated:YES completion:nil];
InitialViewController* controller = (InitialViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"Initial"];
[self presentViewController:controller animated:NO completion:nil];
What you are doing is not "returning" to the tab bar. Instead, you are presenting a completely new tab bar. Now you have two tab bar interfaces. Don't do that.This is sufficient to dismiss:
[self dismissViewControllerAnimated:YES completion:nil];
To change tabs, you need a reference to the existing tab bar controller (not a different one). Then you can just say:
[theTabBarController setSelectedIndex:0];
If you know for a fact that you want to do that when you return from the modal controller, you can even do that at the time you present the modal controller.
Related
iPhone project/iOS 7.1/objective-C Due to circumstances, i have presented a navigation controller which contains a view controller which in turn contains a web view.All of the before said are added programmatically (i.e. no .h,.m or xib files).How do i dismiss the navigation controller?
P.S: I've created all these in a method.There is no property or instance available for the navigationcontroller.
you have to create on barButtonItem on navigation bar like "Back" or "Done" and on it's click event you should write :
[self dismissViewControllerAnimated:YES completion:nil];
This should be very straightforward, however I cannot figure it out which is extremely frustrating.
I have 2 view controllers, each embedded in a navigation controller, and on the 2nd VC I have a button which when pressed should dismiss/pop this view and essentially go back. I have tried both of these and neither works:
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
Help please?
In Case Using Push/Pop navigation scheme :
Make sure you are embedding the navigation controller properly to the view controller from which your navigation starts.
And also make sure you are using push segue to show the second view controller.
On the other hand : if you are using model segue to present the view controller, no need to embed the navigation controller and this will work
[self dismissViewControllerAnimated:YES completion:nil];
I have a tab view controller with a navigation controller. In the first tab item I click on a button in a view that pops up a view with animated: YES.
Then when that view is done I hit another button that dismisses it. Like:
[self dismissViewControllerAnimated:NO completion:^{
ProfilesViewController *profile = [[ProfilesViewController alloc] init];
[self.navigationController pushViewController:profile animated:YES];
//SHOW YOUR NEW VIEW CONTROLLER HERE!
}];
But everytime this code runs, it dismisses the view, DOES NOT push the profiles controller, and shows the view from the first tab bar item.
How do I push the ProfilesViewController to the screen with a Back arrow?
If you are using dismissViewControllerAnimated to dismiss that means that the VC is presented modally. As such, it doesn't have a navigation controller (so self.navigationController is nil) and thus it can't push anything into the navigation controller.
You should really add a property to the controller which is a delegate or a completion block which can be used to push the controller from another controller (the one that presents it) to dismiss and push the controller.
A second option is to pass the navigation controller, it's a similar amount of code to using a block but not so good.
A crappy option is to use the parentViewController to find the appropriate navigation controller, but that sucks for many reasons.
I'm developing an iPad App using storyboards. In this app when the user click on "preferences" appear a modal View. One button of this view send the user to another View Controller (but this view has an action bar to go back to his root view controller), but when user taps the action bar back button nothing happen (it's called navigationController popViewControllerAnimated), the user continue in the same view.
Can anyone help me??
Thanks.
UPDATE:
The code to handle the back button:
- (IBAction)btnBackTapped:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
I'm using Segue (from storyboard) to call this View Controller:
When the user click on "Meus Favoritos"
They will be redirect to this page:
The segue is with a Modal (from image one to two)...
When you are presenting a View Controller modally, it is likely not within a Navigation Controller, so probably the reference to navigationController in your code is nil, can you check that?
If you are presenting your View Controller modally this will work instead
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
However, if you actually want to use a Navigation Controller, you should embed the View Controller that is presenting the Preferences View Controller in a Navigation Controller and present the Preferences View Controller with a show segue instead of a modal one.
My app has two distincts modes. There's a tab bar controller in the app delegate. There are two tabs, both using subclassed view controllers. The two view controllers essentially contain a nav controller each. The nav controllers have their root view controller, and normally when changing screens, I just push and pop controllers of the respective nav controller. This has the (normal) effect that the bottom tab bar is always visible, all great and sound.
This one time I'd like to present a screen modally however, so that the user can't do anything else than confirm or cancel the page using two buttons, ie I want to hide also the bottom tab bar. This would be a case for presenting the view modally I thought, but the view is presented within the nav controller bounds it seems, so the bottom tab bar is still visible, and this causes confusion in navigation the app. I'm not sure how it's possible that the modally presented view is not hiding the tab bar. Most of the questions around here seem to have the problem the other way around (wanting to (incorrectly) present a modal view and leave the tab bar visible).
These are my attempts:
[self presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
[self.tabBarController presentModalViewController:controller animated:YES]; // nothing is displayed. The new controller is instantly deallocated.
[self.navigationController presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
Investigating this, the self.tabBarController is actually nil. There seems to be no link back to the tab bar controller... I guess, to display modally on top of the tab bar, I need to get a link to that tab bar controller?
I seem to have found a solution, I'm not sure it's kosher, because somehow I wasn't able to use the self.tabBarController pointer of the view controller in which I start the view controller call.
What I did was reach for the app delegate, the app delegate having the tab bar controller defined as a public property. I could use that tab bar controller property to modally display my view controller over everything on the screen.