2012-02-09 58 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