views:

161

answers:

2

Short version:
I'm alloc/init/retaining a new UIViewController in one UIViewControllers viewDidLoad method, adding the new View to self.view. This usually works, but it seems to mess up orientation change handling of my iPad app.

Longer version:
I'm building a fairly complex iPad application, involving a lot of views and viewcontrollers. After running into some difficulties adjusting to the device orientation, I made a simple XCode project to figure out what the problem is.

Firstly, I have read the Apple Docs on this subject (a small document called "Why won't my UIViewController rotate with the device?"), and while I do believe it has something to do with one of the reasons listed there, I'm not really sure how to fix it.

In my test project I have an appDelegate, a rootViewController, and a UISplitViewController with two custom viewControllers. I use a button on the rootViewController to switch to the splitViewController, and from there I can use a button to switch back to the rootViewController. So far everything is great, i.e. all views adjust to the device orientation.

However, in the right viewController of the splitViewController, I use the viewDidLoad method to initialize some other viewControllers, and add their views to its own view:

self.newViewController = [[UIViewController new] autorelease]; [newViewController.view setBackgroundColor:[UIColor yellowColor]]; [self.view addSubview:newViewController.view];

This is where things go wrong. Somehow, after adding this view, adjusting to device orientation is messy. On startup everything is fine, after I switch to the splitViewController everything is still fine, but as soon as I switch back to the rootViewController it's all over. I have tried (almost) everything regarding retaining and releasing the viewcontroller, but nothing seems to fix it.

As you can see from the code above, I have declared the newViewController as a property, but the same happens if I don't.

Shouldn't I be adding a ViewController's view to my own view at all? That would really mess up my project, as I have a lot of viewControllers doing all sorts of things.

Any help on this would be greatly appreciated...

A: 

I had the same problem, seams resolved by removing from the parent view the "autoresize subview" option in IB.
Select the view a then: Inspector -> Attributes (first tab) -> drawing.

Cesar
A: 

Hi,

I am new to iPhone development and to this forum also ... wanted some help regarding the similar issue ...

In My App The Hierarchy is like this ...

  1. AppDelegate -> ViewController -> From Here I wanted to switch to another View
  2. Can I add a View Controller or Navigation Controller to This View Controller?
  3. I tried for the same as well to display the modal view too ...
  4. There is no exception for the code, but still the next view didn't get displayed

Plz, Can anybody focus on the solution?

Kranti Bhange