Search code examples
iphoneipaduinavigationcontrollerrootview

Setting rootViewController for ipad 3.2 doesnt work


i did a simple navigationbased app. it works on iphone very well, but it doesnt work on ipad 3.2 simulator and device.

in applicationdidfinish event;

MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
[self.navigationController pushViewController:viewController animated:NO];
self.window.rootViewController = self.navigationController;
[viewController release];

it says for this line:

self.window.rootViewController = self.navigationController;

[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x4c22dd0

but it works on ipad 4.2 and over.

how can i solve it for ipad 3.2?


Solution

  • UIWindow did not have a rootViewController property in iOS < 4.0. Therefore, you will need to check the version (google it) and then either set the rootViewController, or add the navigationController's view as a subview to the window as below, based on what version your user is running.:

    [self.window addSubview:self.navigationController.view];
    

    quick edit: to check if you can use the rootViewController property, you can check if [self.window respondsToSelector:@selector(setRootViewController)] returns TRUE or FALSE.