I have a UINavigation controller setup. I was hoping to do this:
From one of the views, I presentModelViewController:animated:, the user selects one of three options, after selecting I want the UINavigationController behind the modal view to change (the user will not see this), then I want to dismissModalViewControllerAnimated to reveal the new view.
Is this possible using the built-in modal view? Or will I need to create a view, add/animate it to the rootViewController so its not in the same stack as the UINavigationController?
Thanks!
A modal view is a view you show modally on top of another view to interrupt the user from the current task. If I understand you correctly, you need two modal views and the selection user make on first modal view will decide what will show as the second modal view. Is that right?
If that's the case, you can make your main view to be the delegate of your first modal view, and send data back to the main view when the user makes a selection, and then main view dismiss the modal view (it's the main view's responsibility to dismiss it). And then based on user's input, you create another view and pop it modally. To make it animate correctly, you need to set the animation of the dismissing of the first modal view to be NO, and then make the animation of populating second modal view to be YES.
Hope this helps.
Related
Im writing an application which the main view controller is a UIViewController. It has some icons in a grid and I want to dismiss (sliding down) this grid when one of the icons is clicked. This I've done already. The problem is: when the grid is dismisseed I want another View to come from the top of the screen. This view is in this same root view controller. But I want to display the content of other view controllers in this view. For example: I want this view to show a UINavigationController with a UITableView inside it, so the user can navigate through TableViews.
I'm doing this:
HorariosViewController *horarios = [[HorariosViewController alloc] init];
[vuashView addSubview:horarios.view];
HorariosViewController is a UINavigationViewController. It shows me only a blue NavigationBar and changes like self.navigationItem.title = #"Title" won't work.
Thanks!
You can show another view controller's views as subviews but their outlets and actions remain linked to their original view controller unless you write code to make new connections, so self.whatever shouldn't be expected to affect the other view controller's properties.
(Also, if HorariosViewController is a UINavigationController, it shouldn't be created as a UIViewController.)
One approach is to have the navigation controller already there, with the icon grid presented modally on top of it. (you can set the view up this way without animations, so the user doesn't see the navigation controller underneath).
Then, when it's time for the grid to go away, it can call dismissModalViewController on itself with animation.
I have a modal that I am calling presentModalViewController to display from a custom menubar. This menubar is overlaying a viewcontroller that is pushed from a tableView cell.
Now... that all being said, I need to find some way to jump the user back to the root of the tableView from the modal screen. Is this possible? I've been fighting with this for the past couple of hours with no results.
If you're starting from a tablview, drilling down to a detail view via a navigation controller, and then presenting a modal view controller on top of that detail view, you'd have two steps to get back to your list/tableview: First you'd dismiss your modal view controller, then you'd pop your detail view off your navigation stack.
That should put you back where you started (at the tablview), if I'm reading this correctly.
You could pass a reference to the navigation controller to the modal view, and then immediately after calling dismissModalViewControllerAnimated, you can use the reference to the navigationController to pop back to the root view controller.
After a modal view controller is dismissed, is there any delegate method called to bring the parent view controller to the front?
I ended up using delegation from Apple's View Controller Programming Guide for iOS :
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
When it comes time to dismiss a modal view controller, the preferred approach is to let the parent view controller do the dismissing. In other words, the same view controller that presented the modal view controller should also take responsibility for dismissing it whenever possible. Although there are several techniques for notifying a parent view controller that it should dismiss its modally presented child, the preferred technique is delegation.
There was a good example in the CoreDataRecepies sample code when adding a recipe that fit what I was trying to do.
i.e., at the "same time" view[Will|Did]Disappear: is being called on the modal view controller as its view is being dismissed, the view[Will|Did]Appear: are sent to the view controller that is being revealed
the code in here should not really need to differ from the reveal code you used when it was first displayed,
if you need data passed back from the modal controller to the one that displayed it, generally the code that dismisses the modal controller lets the other one know
parentController.item = self.chosenItem;
[parentController dismissModal…
On the iPhone, we can simply use (void) viewDidAppear:(BOOL)animated; to perform actions when a view becomes the focus. In some events, we have a modal view with another modal view on top of it and, on the iPhone, closing the topmost modal view will fire the viewDidAppear for the lower modal view.
This is not the case for the iPad, as the view stays "visible" even though it's behind another modal view. Is there any way to tell from within a UIViewController when the view itself becomes the active view?
Can't you just use when the modal view controller's view disappears?
When the modal view's controller recieves the viewWill/DidDissapear you know that the original view is visible again.
EDIT:
in the viewDidDissapear of the modal viewcontroller add this:
[self.parentViewController viewDidAppear:animated];
This will make the viewDidAppear method be called as it is on the iPhone.
You don't need to set self.parentViewController at all, as it is done for you in the presentModalViewController method (the one your use to display the modal view controller)
try checking the value of [theUIView isFirstResponder]
it should be True for the view that has the focus of the keyboard, etc.
My application presents a modal view (A) from the main view that lets the user make a selection. When they make that selection it opens a second modal view (B) on top of the first one (A).
When I'm done with the second modal view (B), and want to dismiss it, I would like to dismiss the first one (A) and the second one (B) at the same time as I no longer need the user to return to that one (A) either.
The only thing I came up with is:
[self.parentViewController.parentViewController.parentViewController. dismissModalViewControllerAnimated:YES];
It works, but it just doesn't look correct. Is this OK to do or is there a more accepted way to do this?
I don't think that your way is wrong. It is what Apple documentation recommends:
If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
(UIApplication.sharedApplication().delegate! as! AppDelegate).navigationController?.viewControllers.first?.dismissViewControllerAnimated(true, completion: nil)