我正在关注用于Modaly的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;

在我的ViewDidload中

模态控制器显示良好,除了没有条,所以我不能离开该屏幕。

有帮助吗?

解决方案

您需要在实际提出弹出窗口之前添加它。

在创建模态弹出窗口的位置,您需要先在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];

这将使模态视图成为您要编辑的导航栏。

其他提示

或者, ,您可以维护故事板的障碍。在XCode中,选择您要尝试过渡到导航控制器中的视图控制器。

现在,在该视图控制器的视图载荷中,添加:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel)];

最后是回调:

- (void)cancel {
    [self dismissModalViewControllerAnimated:YES];
}

或者,如果您只需要栏的外观,而不是完全的功能,则可以从媒体库面板上拖动导航栏(Uinavigationbar)或工具栏(UIToolbar)控制,然后从那里进入。

我也有类似的困境,从而在contavewiew中加载了一个UitaiteViewController。 ContainerView在一个以模式方式展示的UiviewController中。

我像您一样,需要导航栏具有标题和一个完成/取消按钮。

溢出堆栈后,我终于做到了 -

将UIVIEW作为IB中表视图中的第一项拖动。这会自动获得44分的高度,然后抢到顶部。这也使我的第一部分向下移动。

我在此视图中拖动了一个Uibutton(Done Button)。创建了一个iboutlet,并打电话给

    [self dismissViewControllerAnimated:YES completion:nil];

免责声明:

1)这个假航 - 将与桌面一起滚动。 2)这可能不是机器人要求的解决方案,但是对于其他可能正在寻找类似物品的人来说,这是一种选择。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top