I'm doing the following:
[self.parentViewController dismissModalViewControllerAnimated:YES]
This code fails using the Simulator but works with no issues on the phone itself. The Simulator's console shows no erros. I used NSLog statements to pinpoint this line of code as the culprit. When running on the phone, however, the console(window>organizer) shows that the above code is executed and the application proceeds forward with no problem.
When running the code in debugger, the following statement appears at the bottom of the Xcode debug window:
GDB: Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.)
Then a window dispalys stating: Loading 43672 stack frames. (that sounds bad)
In the debug window the following line appears numerous times:
[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]
Without getting too deep into my code, does anyone know about or have experience with this type of condition?
Thanks
Why you don't just call [self dismissModalViewControllerAnimated:YES]. It is quite enough to close you modal view controller.
I know, it isn't answer for your question, but maybe it helps to avoid your issue.
I think where you are calling this from is key but you don't say where this code is.
I suspect that dismissing your parentVC is causing this code to get executed again, which tries to dismiss the parent again... basically an infinite loop.
Thanks for the responses.
Aleksejs - I've tried your suggestion with no success. Thanks for making sure I've done the obvious first.
progrmr - I think you are probably correct - when and where I dismiss the modal view is the key and I'll look into how I'm doing this. I may need to re-architect how I'm handling my views.
This is frustrating because the issue does not happen on the iphone itself, only in the Simulator. And, I just confirmed that with the same MacBook Pro the error does not present itself in the Simulator when I'm working from home - the problem only occurs at my office. Strange, eh?
I'll keep digging and report my findings.
Thanks again.
Update - I didn't solve the problem but instead avoided it by re-structuring things. Before, in applicationDidFinishLaunching:, I presented a Login view controller as a modal view. I then need to display a EULA view controller so the user can agree to some legal stuff. I think my problem was that I was presenting the EULA view as a modal from the Login view (which is also modal). The order in which the modals were being presented/dismissed, I think, was the problem (as progrmr had suspected).
How I avoided the issue? I took the time to learn about the delegation pattern. Now, each modal view (Login and EULA) are presented within the app delegate class and I use delegates to callback when certain actions are taken on the modal views.
You shouldn't use self dismissModalViewControllerAnimated if self doesn't actually have a modalViewController. Just create a protocol that delegates the dismiss from the modal view controller back to the parent. when you push the modal view controller, assign the delegate, then when you want to dismiss it call [self.delegate dismissMe] which in turn calls [self dismissModalViewControllerAnimated:...] on the delegate (the parent).
[[Picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
Instead of
[[Picker parentViewControl] dismissModalViewControllerAnimated:YES];
and
[self presentViewController:picker animated:YES completion:nil];
Instead of
[self presentModalViewController:picker animated:YES];
Related
Does [self viewDidAppear:YES]; in the viewDidLoad section of code ensure that the viewDidAppear section of code will run?
Based on feedback from a small subset of our users, it appears for whatever reason that the code I have written in the viewDidAppear section of the main menu's view is not running for them - but it works perfectly well for the majority of users and in all my testing. I'm hoping that by adding [self viewDidAppear:YES]; this will fix the issue for those devices that for some reason were not calling viewDidAppear...
What do you guys think?
I think that's a horrible idea, personally. I think you're better off finding out WHY viewDidAppear didn't execute for that subset of users. You may only be treating a symptom of a greater problem by just 'fixing' what appears to be wrong.
ViewDidAppear may not be getting called if its on a view controller that is nested in another view controller and running on an older OS. Before iOS 5, delegate commands did not always get forwarded to child controllers.
You should never call delegate methods directly.
I have a scenario where I present a modal view controller from the main window's rootViewController. While it is loading the contents of this modal, I am switching to another loading window which I make key and visible.
This window acts as a loading indicator and does not allow the user to interact with the app. When it is done loading, I switch back to the main window by making it key and visible. When I do this, the modal is force closed and the app is no longer able to present modals.
Interestingly enough, if I execute [UIWindow makeKeyWindow] when switching back to the main window, there are no issues. [UIWindow makeKeyAndVisible] is what's causing the issue. Is [UIWindow makeKeyWindow] an acceptable alternative?
This is iOS 5 only. No issues in iOS 6. I am not supporting iOS 4. Does anyone know what might be happening here?
I got the same behaviour, and as documentation states that makeKeyAndVisible method is a convenience method it seems to me legit to substitute makeKeyAndVisible call with working code:
[window makeKeyWindow];
window.hidden = NO;
Have no idea what's wrong, but it looks like a bug.
It is definetly bug in iOS 5 UIWindow implemetation. I faced this strange behaviour and Aleksey's answer is the way to go.
I'm sharing this as it took me A while to figure out. This is if you need to get rid of a double stack of modal views IF it is pressent.
if(self.parentViewController.parentViewController)
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
else
[self dismissModalViewControllerAnimated:YES];
I have a view that sometimes gets called from a modal view. In that case I would need to get rid of both views at the same time. While dealing with the situation where it was the only modal view. This worked.
As of xCode 4.2 this is no longer working, The new way to deal with this situation is:
if(self.presentingViewController.presentingViewController)
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES];
else
[self dismissModalViewControllerAnimated:YES];
As pointed out by #Hollance in a relevant thread of mine:
iOS 5 SDK treating UIViews differently
"There is a new property in iOS 5 named presentingViewController. The meaning of parentViewController got changed a bit with the new container view controller API, so it may not always be set when you think it is. That's what presentingViewController is now for."
My app is crashing when I am trying to dismiss a modal view using:
[self dismissModalViewControllerAnimated:NO];
This is the flow of the application:
ViewController (My app landing screen) --> Push couple of view controllers --> Show the modal view.
Now, is my intention of canceling the modal view from the same modal controller (self) is correct or should I cancel it from somewhere else.
I had tried passing the object of the last conroller class in the stack to my modal controller and tried following code but it still crashes:
[self.lastStackObj dismissModalViewControllerAnimated:NO];
Appreciate if someone can guide!!!
try this :
[self.parentViewController dismissModalViewControllerAnimated:NO];
maybe you're releasing an already released object in the dealloc.
try commenting all the release statements in the dealloc & then try running, hopefully it wont crash.
You can fix it by finding the variable & releasing it only once.
There maybe other problems causing this too. But this is the first thing i'd look for.
If I dismiss the the modal VC and present it (or another one) again in less than a certain amount of time, it does not appear.
Am I missing something?
Yes, you can't do that. I'm assuming what you did is something like this:
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController:myNewController animated:YES];
This doesn't work. I don't know exactly why, but it is related to the animations I believe. Your options are to either dismiss the first one without animation, or else wait to present the new one in viewDidAppear of the parent, (or possibly viewDidDisappear for the previous modal view, not sure if that works though).
You cant dismiss two modal view controllers right after another, aside from what the other poster suggested, you can wait a small amount of time before dismissing the other modal view, for example
[self performSelector:#selector(method) withObject:nil afterDelay:.5];
where the method called just dismisses your other modal view.
The snippet of code performs the selector after .5 seconds and can be used when having animation timing problems like the one you describe, to seperate the call times in order for them to execute properly.