application crashing on ipod touch but not on iphone emulator
I followed the apple tutorial "Your First iOS Application" step by step and it works perfectly on the iPhone emulator.
But when I attempt to deploy it on an ipod touch, the application crashes.
here is the problematic method :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MyViewController *acontroller = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
[self setMyViewController:acontroller];
[[self window] setRootViewController:[self myViewController]]; // crash here
[sel开发者_如何学运维f.window makeKeyAndVisible];
[acontroller release];
return YES;
}
And here is the error message :
011-04-13 18:07:53.730 ios_HelloWorld[865:207] *** -[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x119520
2011-04-13 18:07:53.754 ios_HelloWorld[865:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x119520'
2011-04-13 18:07:53.770 ios_HelloWorld[865:207] Stack: (
843631901,
849079828,
843635709,
843131673,
843094080,
11801,
857435720,
857434728,
857767424,
857765436,
857763988,
875472868,
843380011,
843377695,
857431048,
857424432,
11553,
11476
)
terminate called after throwing an instance of 'NSException'
Consider that I have followed the tutorial step by step (and re-did it by my own) and it always crashes at this spot.
Any idea?
thanks
KiTe
self.window.rootViewController vs window addSubview
Have a look at the documentation, the desired property is not available on that iOS Version. You will have to update or build in some conditional workaround.
rootViewController The root view controller for the window.
@property(nonatomic,retain) UIViewController *rootViewController Discussion The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.
The default value of this property is nil.
Availability Available in iOS 4.0 and later.
The setRootViewController method is only available in iOS 4.0 and above.
精彩评论