3

My problem seems to be a bit weird, I have a custom UITarBar which manages several UINavigationControllers with a UIViewController that presents those NavControllers modally on a UITabBar button touchUpInside, so in iOS 5 my app is crashing because of the dismissModalViewControllerAnimated: method ... And if change the dismiss method to the new one on iOS 5 (dismissViewControllerAnimated:completion:) it does not dismiss the NavController. Here is some code on how I'm changing controllers:

- (void) changeController
{   
    if ([self.generalViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
        [self.generalViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
    } else {
        [self.generalViewController dismissModalViewControllerAnimated:NO];
    }
    [self.anotherNavController.view addSubview:customTabBar];
if ([self.generalViewController respondsToSelector:@selector(presentViewController:animated:completion:)]) {
        [self.generalViewController presentViewController:anotherNavController animated:NO completion:nil];
    } else {
        [self.generalViewController presentModalViewController:anotherNavController animated:NO];   
    }

Everything is managed in the AppDelegate. Thanks in advice.

EDIT: I found something on this post dismissModalViewControllerAnimated: (and dismissViewControllerAnimated) crashing in iOS 5 and did what he did (presented the first viewControllerAnimated animated) and then everything like I had before the iOS 5 checks for new presentViewController's selectors and everything works fine on simulator but not on device ..

Community
  • 1
  • 1
Herz Rod
  • 831
  • 8
  • 21
  • Your first condition test if the generalViewController reponds to te selector. If it's evaluated to true then this message is sent to presentingViewController??? – Jaffa Oct 19 '11 at 15:52
  • Yeah because I've been reading that is the way to do so in iOS 5 – Herz Rod Oct 19 '11 at 16:00
  • 1
    The check is necessary if you want the same app to run on iOS 4.x and earlier; if you're only targeting iOS 5 there's no need to check. – benzado Oct 19 '11 at 16:26

1 Answers1

0

I am unsure about your first lines, and think the first lines should perhaps be:

 if ([self.generalViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
    [self.generalViewController dismissViewControllerAnimated:YES completion:nil];

You have an extraneous .presentingViewController in the second line of the above presently. I see in your comment above you have a rationale for it, but have you tried the alternative?

Regardless, I had a related problem with the move to iOS 5, and found that the solution was to simply send the dismiss commands thusly:

 [self dismissViewControllerAnimated:YES];

I suggest you try it. It worked for me, and also still worked in iOS 4.2 as well when I ran the code there...

Edit: Correction, it was dismissModalViewControllerAnimated that I was correcting. However, in that case I found that just sending the message to self rather than targeting a view controller was what fixed the problem of not being able to dismiss the view, and worked in both iOS 4 and 5... Couldn't hurt to just try.

Duncan Babbage
  • 19,972
  • 4
  • 56
  • 93
  • The actual problem was something else and not the way of dismissing the controller, kind hard to explain because it wasn't even related to my original question but thanks for your opinion. – Herz Rod Nov 07 '11 at 16:19