1

I've a weird problem. I'm using a navigationController and want to add a subview (a MBProgressHUD) to the navigationController.view.

Everything is absolutely fine under iOS4. But if I switch WITH THE SAME PIECE OF CODE to iOS5 the app crashes because the navigationController.view is now nil.

So there must be something which works under iOS4 but not under iOS5 in my code.

Has anybody a guess what I'm doing partly wrong there? Is there any difference between iOS4 and iOS5 setting up a view?

I'm somehow lost at the moment, because I've no general error I can search for but more a specific ones in context of iOS5.

I know this is a really general description, but I think it would be too much to post my complete code here.

So I really appreciate every single hint because I've absolutely no clue what's wrong there.

Thanks,

Andreas

Update 1:

I know that the problem occurs because of a tabBarController.

It's the following way:

When a user clicks on a row in a UITableView, the app opens a tabBarController including three views consisting each of it with a UINavigationController and a view in it.

So I initialize this construction with:

    self.tabBarController = [[UITabBarController alloc] init];
    SomeUIViewController* tabOne = [[SomeUIViewController alloc] init];
    tabOne.tableViewContext = self.conferenceContext;

    SomeUIViewController* tabTwo = [[SomeUIViewController alloc] init];
    tabTwo.delegate = tabOne;

    SomeUIViewController* home = [[SomeUIViewController alloc] init];

    [self.tabBarController setViewControllers:[NSArray arrayWithObjects:tabOne, tabTwo, home, nil]];

    [self.navigationController pushViewController:self.tabBarController animated:YES];

    [home release];
    [tabTwo release];
    [tabOne release];

So the error seems to be within these lines of code. Because if I only init tabOne-View without the tabBar all things work perfectly also under iOS5. But if I init a tabBar with these lines of code I get the error.

Can somebody explain me what's wrong there under iOS5 perspective, because this code works perfectly under iOS4.

Update 2 (Important)

So, I think the problem is the navController. My structure is the following: window->navController->tabBar.

And it seems to be the case, that under iOS4 the app can access the navController within a tabBarView, but not under iOS5.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
andi1984
  • 676
  • 10
  • 27
  • Where did you alloc and init the tabBarController? – dasdom Nov 08 '11 at 14:04
  • Oh sorry, I alloc and init the tabBar right before the other code (see update above). And I'm releasing it in the dealloc method of the same UIViewController. – andi1984 Nov 08 '11 at 15:14
  • Depending on your property declaration this `self.tabBarController = [[UITabBarController alloc] init];` could be a leak. – dasdom Nov 08 '11 at 15:36
  • You're right. I had a nonatomic, retain property. So I only released the tabBar once but retained it twice. So I added now an autorelease on it. So the leak shouldn't be there now. Same for navController where I had the same issue. But still it doesn't work. It must be a problem iOS5 specific, because it still works under iOS4. Really weird issue. – andi1984 Nov 08 '11 at 16:07

2 Answers2

2

This is a logical problem. A navigation controller is a container for view controllers. Therefore it has no view associated with it. Try something like this:

UIView *currentView = [[myNavigationController visibleViewController] view];
dasdom
  • 13,975
  • 2
  • 47
  • 58
  • Thanks! But it didn't solve my problem. But anyway: thank you for this. Do you have seen my update above? Do you have a guess for that? – andi1984 Nov 08 '11 at 12:59
2

So, I've finally find out how to fix this problem. But I don't understand why it's only occuring only in iOS5.

So the problem is, that I wanted to access a navController in viewDidLoad. Actually the navController is not linked until this point in iOS5. That's why the error occurs. If I move the code snippet in viewWillAppear all works fine.

But why this is only occuring in iOS5 and why has it worked in iOS4 with viewDidLoad?

That's the final question still existing in my head.

But now the app runs in iOS5 and I'm partly happy ;-)

andi1984
  • 676
  • 10
  • 27
  • Note that there is a change in iOS 5: parentViewController is no longer set for modal views -- you must use presentingViewController instead. (And, of course, presentingViewController isn't available in iOS 4.) – Hot Licks Nov 28 '11 at 17:23