2011-07-01 92 views
0

我在導航欄或控制器頂部製作tableview時遇到了問題。初始化導航欄

我有這樣的一段代碼,

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UINavigationController *addNavCon = [[UINavigationController alloc]initWithNibName:@"Welcome" bundle:nil]; 
    self.navigationItem.rightBarButtonItem = self.addButtonItem; 
    self.navigationItem.leftBarButtonItem = self.editButtonItem; 




    [self createEditableCopyOfDatabaseIfNeeded];  

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil]; 

    NSString *documentDirectory = [self applicationDocumentsDirectory]; 
    NSString *path = [documentDirectory stringByAppendingPathComponent:@"notebook.plist"]; 

    NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path]; 
    self.Notes = tmpArray; 
    [tmpArray release]; 



} 

然而,在導航欄上從來沒有出現,而表做精。我可以知道代碼有什麼問題嗎?

非常感謝

回答

1

您已經創建的UINavigationController實例,但從來沒有將它添加到任何東西。您需要將其添加到當前層次結構中,否則它將不會顯示。

如果您希望將navController添加到整個應用程序,那麼你應該

- (void)applicationDidFinishLaunching:(UIApplication *)application 

{ 

    UIViewController *rootController = [[MyRootViewController alloc] init]; 

    UINavigationController *navigationController = [[UINavigationController alloc] 

           initWithRootViewController:rootController]; 

    [rootController release]; 



    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    [window addSubview:navigationController.view]; 

    [window makeKeyAndVisible]; 

} 
+0

謝謝你這樣做在App代表,這是非常有幫助的。 – Clarence

+0

但是如果我不想將它添加到整個應用程序呢?如果我只是希望它出現在應用程序的一個視圖中,該怎麼辦?我試圖把它們放在viewDidLoad中,但不起作用。謝謝 – Clarence