2011-07-01 54 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