我的程序在iOS 4/Xcode3中运行良好。我最近升级到了最新版本Xcode4/iOS5。我在下面的代码行上得到了一个"SIGABRT“:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];这一行是在应用程序的委托中完成启动的。下面是一些示例代码:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
rootViewController = [[MyCustomViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.window = window;
window.rootViewController = rootViewController;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}任何帮助都是非常感谢的。
发布于 2012-02-09 16:44:39
初始化window的“正常”方式是这样的:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = [Myclass alloc] init...你是用另一种方式做的
rootViewController.window = window;然后
window.rootViewController = rootViewController; ???这真的适用于旧的xcode吗?
发布于 2012-02-09 16:47:39
如何使用你的applicationDidFinishLaunching方法是非常奇怪的。
如果您希望将UINavigationController添加为window rootViewController,然后使用MyCustomViewController的实例初始化导航控制器,请执行以下操作:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// code for creating a window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
MyCustomViewController* myCustomViewController = [[[MyCustomViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:myCustomViewController] autorelease];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
}应用程序委托.h中的window类似于
@property (nonatomic, strong) UIWindow* window; // using ARC或
@property (nonatomic, retain) UIWindow* window; // using not ARC该属性也是在应用程序委托.m中合成的,如下所示
@synthesize window; 一些注意事项:
当你使用window.rootViewController时,你不需要调用[window addSubView:someview]。iOS 4已经为您处理过了。
您确定您的代码可以在较旧的sdks中运行吗?
希望能有所帮助。
https://stackoverflow.com/questions/9206687
复制相似问题