2012-02-09 79 views
0

我的程序在iOS 4的/ Xcode的工作完美3.我最近升级到最新版本的Xcode 4/5的iOS我得到以下行 “SIGABRT”:的iOS的Xcode 4的UINavigationController

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]; 
} 

任何帮助表示赞赏。

+0

无法诊断,无需更多的代码。初始化rootViewController时可能出错。 – danielbeard 2012-02-09 07:13:02

+0

对不起,添加更多代码。 – user1120008 2012-02-09 07:20:37

回答

1

“正常” 的方式来初始化window是这样的:

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
window.rootViewController = [Myclass alloc] init... 

你这样做反过来与

rootViewController.window = window; 

然后

window.rootViewController = rootViewController; ??? 

难道说真的与旧的xcode一起工作?

2

如何使用applicationDidFinishLaunching方法很奇怪。

如果wanto添加UINavigationControllerrootViewControllerwindow,然后初始化导航控制器的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]; 
} 

window您的应用程序委托中.h就像

@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中工作吗?

希望它有帮助。

+0

你为什么要在void方法中返回YES? – Eimantas 2012-02-09 08:51:40

+0

@Eimantas我修复了它,谢谢。我犯了一个错误,因为我认为它是写入' - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions'。干杯。 – 2012-02-09 08:58:19

相关问题