Reputation: 68750
In my apps I check to see if the device is running less than iOS 5.0 and add the main view to the Window like this:
if (UIDevice.CurrentDevice.CheckSystemVersion(5, 0))
window.RootViewController = tabBarController;
else
window.AddSubview(tabBarController.View);
// make the window visible
window.MakeKeyAndVisible();
My question is: Is this really needed? Can I just do this always:
window.RootViewController = tabBarController;
Follow up question: Will this work when iOS (more than 5.x) theoretically comes out?
Upvotes: 3
Views: 100
Reputation: 26495
If you don't have the above check for iOS 5.0, your apps will crash on older OS's. Older OS's do not have the RootViewController value on UIWindow.
Specifically, RootViewController is supported in iOS 4 and later, but required in iOS 5 and later: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html
The code will still work when iOS 6 comes out, since CheckSystemVersion()
makes sure you are greater than the values passed in.
Upvotes: 3