iOS:尝试将导航栏添加到Modal UITableViewController

Bot*_*Bot 3 objective-c uitableview ios5

我正在关注CoreDataRecipes应用程序,以便在我想要添加新项目时显示添加屏幕.但是我不能让栏显示在顶部,所以我可以按'完成'或'取消'.

在调用模态控制器的xib中,我将+按钮链接到通过IB模式向上滑动控制器.

我的模态控制器中有以下内容

self.navigationItem.title = @"Add";

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(save)];
    self.navigationController.navigationBarHidden = NO;
Run Code Online (Sandbox Code Playgroud)

在我的viewDidLoad中

模态控制器显示正常,但没有条形,所以我不能离开那个屏幕.

Seb*_*eek 13

您需要在实际呈现弹出窗口之前添加它.

在创建模态弹出框的位置,需要先在UINavigationController中创建它.

所以,请执行以下操作.

 PopoverView *foo = [[PopoverView alloc] initWithNibName:@"PopoverView" bundle:nil];
 // Here you pass through properties if you need too.
 // ...
 UINavigationController *navC = [[UINavigationController alloc] initWithRootView:foo];
 [foo release];

 [self.navigationController presentModalViewController:navC animated:YES];
Run Code Online (Sandbox Code Playgroud)

这将为模态视图提供您尝试编辑的导航栏.