我在制作顶部有导航栏或控制器的表视图时遇到问题。
我有一段代码,
- (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];
}
但是,导航栏永远不会显示,而表运行良好。我可以知道代码出了什么问题吗?
非常感谢
您已经创建了UINavigationController
的实例,但从未将其添加到任何内容中。您需要将它添加到当前层次结构中,否则它将不会出现。
如果你想将导航控制器添加到整个应用程序中,那么你应该在的应用程序代理中这样做
- (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];
}