I am just presenting modal view controllers one after the another and not dismissing that. Because my requirement is such that I want show view controllers one after the another like chain.
1) Will this create memory problem ?
2) If so what is the work around ?
Thanx in advance
Yes you may get a memory or performance problem. I don't think Apple intended/intends for anyone to present multiple modal view controllers one after the other.
Have you seen this : Problem dismissing multiple modal view controllers
I think you should dismiss the current modal before presenting a new one. Always. Always. Always. You don't have to dismiss them animated though, you can dismiss them without animation so you don't see them disappear visually.
If you need to be able to go backwards through the chain of modally presented view controllers then I would instigate a method for doing this. e.g. add properties to your UIViewController subclasses that specify the next and previous viewController (or maintain a history trail of the viewControllers).
To be honest, it sounds like you should be using a navigationController and not presenting the viewControllers modally.
Related
I'm trying to create an app using storyboard which has 4 scenes:
ChooseLoginMethod
EnterLoginData
SuccessfulLogin
MainScene.
What I'm doing right now is the following: I have an UINavigationController which has ChooseLoginMethod as its root view. ChooseLoginMethod has several buttons (for different login methods) which are push segues to EnterLoginData. EnterLoginData has a push segue to SuccesfullLogin and SucessfullLogin has a push segue to MainScene.
The problem is that SuccessfulLogin and MainScene display the back button on the top bar, which makes no sense for the application.
I've tried:
Hidding the top bar on these two Views. Not successful.
Changing the segue to modal. Seems to work, but doesn't feel like the right thing to do.
So what I would like to do is create a segue which breaks the chain of Views which are on the UINavigationController's stack. Is there a proper way to do this in storyboard?
-- edit --
Maybe what I should do is replace the root view ( Set root view for UINavigationController ). This may work, but seems like a programming work-around for something that should be possible to be done in storyboard. Or maybe it is just me not getting the "iOS way of doing stuff".
You had to use setNavigationBarHidden before the viewcontroller appears on the screen, like in viewWillAppear.
But then you can't go back from "MainScene" to the "RootController". So you should do something like popToRootViewController after "SuccessfulLogin" and then pop "MainScene".
I think it's usually best to have your main scene be the root view controller. From its viewDidAppear method, you can present your ChooseLoginMethod controller modally, and from there do modal transitions to your other login controllers. When you get to the end, and you want to go back to the main scene just dismiss the modals from the root view controller -- this will dismiss the first one, and any that were presented from it:
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
My App starts up, and I have a UITabBarController. On the first tab I have a subclass of UIViewController. It's in this class that I have my movie playing functionality. I do not know why, but from this class, I cannot presentModalViewController or presentMoviePlayerViewControllerAnimated. I can however add views as a subView. I found this post, which is essentially what I'm trying to do (present a movie player view controller): How to present MPMoviePlayerViewController from a UITabBarController?
But even keeping a reference to the UITabBarController does not work for me. I'm not really sure why this class has problems presenting a modal view controller, versus in other tabs, I am able to. Any thoughts? Thanks.
After more looking, I found that the problem is I cannot present a view modally within the viewDidLoad method.
First, sorry about my English, I know it's bad, but I'm trying to make it better...
Here is the issue: I'm making an app, with a view controller, with a lot of views... I want to make a button to go back to the main one. I think I have to dismiss the views I pushed. I dont know if that is necessary or if I can push it again directly. If it is, how can I do that? I've tried to put a dismiss method after the presentModalViewController one, but it didn't work.
Any help?
Thank you so much for your help ;)
It hard to tell from your question, but you may be confused by the navigation stack and the modal controllers.
A modal controller gets presented and dismissed using:
presentModalViewController:animated:
dismissModalViewControllerAnimated:
Navigation controllers are pushed and popped using:
pushViewController:animated:
popViewControllerAnimated:
So make sure you are using the correct method to pop or dismiss the view in question.
To present and dismiss a modal view you'll have to use delegation.
Here is an explanation for how to present and dismiss modal views.
Modal views are handled differently than views controlled by the UINavigationController or UITabBarController, which just push them onto a view stack or array of views.
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)
I have been in the process of learning to build iPhone applications for the last two weeks. I've gotten through a fair amount of content, and now I'm trying to create a modal pop up with presentModalView.
I can can successfully create and slide up a view, but I notice that modal views don't provide you with a default navigation bar at the top of the window, which makes sense for flexibility I guess. Most modal views I've seen have a "Cancel" and a "Done" or "Save" button as navigationItems on what looks to be a UINavigationController. My thought then was just to instantiate a navigation controller and push the single view onto the view controller stack, and presentModalView:navController.view ...
Because the view is relatively complex, I was trying to lay out both the UINavigationController, with the bar buttons, and the view I was hoping to push onto the stack in a single xib -- no matter what I try, I can't seem to get the linkages correct. Can you even do this? Or should I create a separate class/xib for the view I'm going to be pushing onto the navigation controller? Seems like a lot of classes and files for one screen, so my feeling is I must be missing something.
At this point, I could have done it programmatically about an hour and a half ago... however, this is a real nag, since IB seems GREAT for some things. Anyone have an experience with a situation like this?
Thanks,
Josh
If you're not going to use this new XIB for navigation, there's no point in making a navigation controller.
In interface builder, simply drag a UINavigationBar to the top of your view, and add a "Done" Button. Now, add an IBAction to the done button to dismiss the view controller. Your ViewController code for the dismiss IBAction should look something like this:
-(IBAction)dismiss {
//Any logic before dismissing the modal view
[super dismissModalViewControllerAnimated:YES];
}