check whether animation from modalViewController is finished - iphone

I had tried presenting a UIPopoverController on a viewWillAppear on a view presented via a modal view controller. However when doing so the UIPopoverController immediately got dismissed. Any idea why this might have happened and the right way to do so?

Don't do any view handling in -viewWillAppear, because there is no guarantee that the view has loaded. Move all implementations into -viewDidAppear for safer execution.

Related

Memory issue in Present Modal View Controller

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.

iOS 5 : -viewWillAppear is not called after dismissing the modal in iPad

I am presenting modal using the following code :
AddName *add = [[AddName alloc] initWithNibName:#"AddName" bundle:nil]
add.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalView:add animated:YES];
And After my work I use following code to go back on my main view.
[self dismissModalViewControllerAnimated:YES];
So it use to call -viewWillAppear by default.
My problem is that,
It was working fine with iOS4.3.
But Its not working with iOS5.
What should I do ? Or Is that any bug in iOS5?
-viewWillAppear is only guaranteed to be called in places where the -viewWillDisappear has also been called. For most modal windows on the iPad, this is not the case, since they don't obscure the entire page.
The solution to your problem will depend on what you need the -viewWillAppear for, but in general, you're likely to need to make a call directly from the same place that you dismiss the modal view controller.
One common mechanism for this, especially in cases where you might use that same modal view somewhere else, is to give the modal view controller a delegate which is called when the view is about to disappear. This will give you a chance to take the responses from the modal window, or even just force a data reload in the delegate view.
Hope this helps.
iOS 5 definitely changed their calls to viewWillAppear and viewWillDisappear. For instance, subviews (View Controller's views as subviews to be exact) in a UIScrollView, viewWillDisappear will get called when you push another view controller onto the stack. However, when the view controller is popped, viewWillAppear does not get called. These methods were never called in iOS 4 on UIScrollView subviews.
This is strange behavior to me. Couple that with the fact that regardless of what should happen, if you could rely on it happening in iOS 4, it should not be working differently in iOS 5. Most of the time, I have no idea in which particular instance each one is called, I usually trial and error it as I'm in the zone coding. If it works the way I like, I move on. Then iOS 5 comes in and throws a wrecking ball into everything.
I have also experienced when a UINavigationController's view is a subview, and a ViewController is pushed on the navigation controller stack, viewWillAppear never gets called in iOS 4, but does get called in iOS 5. Go figure.
I had the same problem.
I found that viewWillAppear isn't get called after dismissing modal but viewDidAppear is. So just try viewDidAppear instead.

Dismiss some views

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.

iPhone - Detect the end of the animation

How can I detect the end of the animation of a modal view (when I do a dismiss)? (I'm talking about MFMailComposeViewController which is not created by myself...)
Thanks
Your modal view controller has a -viewDidDisappear: method that is automatically invoked whenever the view is removed from the screen. You can override this method in your modal view controller to do whatever you like.
Also, you may want to consider implementing the -viewDidAppear: method in the view controller whose view gets revealed by your modal view disappearing.
You can subclass MFMailComposeViewController and overload its -viewDidDisappear:.
#interface MyCtrler : MFMailComposeViewController
#end
#implementation MyCtrler
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// do anything you like
}
#end
I needed to do something after dismissing a modal view, and only when it is sure that the modal view is really gone (been completely dealloc-ed). So viewDidDisappear and its friends in the modal view were too early for me.
The easiest I found was to just delay my code with a NSTimer. When modal view calls its delegate and the delegate invokes removing the modal view, it also queues up the code to be run when the modal view is gone. The timing was something like 300ms or 400ms. (Is there a way to retrieve the actual timing from somewhere?)
Normally to be notified when an animation is complete you set a delegate by sending setAnimationDelegate: to the UIView class.
When a VC is dismissed using [someVC dismissModalViewControllerAnimated:YES] you can't set the animation delegate, but if you send NO instead and do your own animation of the VC's view you can set the delegate and be notified when the animation is completed.

How to Unload a popped view controller?

Using a navigation based view hierarchy. I have a root view controller, and multiple view controllers that branch out from the same when a button is pressed. When a user presses the back button on the UINavigationBar, the current viewcontroller is popped and the display animates back to the rootviewcontroller.
The problem is, I want the viewcontrollers to UNLOAD whenever they are popped. Seems like they are not unloading because when I go back to them they are still in the state they were when they were popped.
How do I unload the viewcontrollers after navigating back to the rootviewcontroller?
-viewUnload is called after the application receives low-memory notification.
It is the default implementation of -didReceiveMemoryWarning that calls -viewUnload.
What you probably want to do is put what you want to do into -viewDidDisappear based on what you've described.
When you pop a viewcontroller from a navigationcontroller, there should be no more references to the viewcontroller left and the viewcontroller should be deallocated at that time. This should give you the results you expected. You can test if the viewcontroller is being deallocated by adding a break point in -dealloc method.
If dealloc does not get called, check if there is a retain cycle. Specifically check if a child object is retaining the viewcontroller.
in -viewDidDisappear why not [self release]; just need to make sure you have a lazy loader so it will load back when needed.