1

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?

fulberto100
  • 313
  • 5
  • 23

2 Answers2

5

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.

Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56
  • great, it works for all iOS version. i think i dont need to check version. because i dont set the view controller in IB. thanks... – fulberto100 Apr 11 '11 at 20:31
1

The correct way is (don't forget ":"!):

if ( [self.window respondsToSelector:@selector(setRootViewController:)] )
    self.window.rootViewController = self.tabBarController;
else
    [self.window addSubview: self.tabBarController.view];
NiKe
  • 581
  • 1
  • 5
  • 4