如何从第二层往下建立UINavigationController(不是从Delegate/RootController层)
在以下情况下使用 UINavigationController 的代码是什么?
- 基本应用程序基于 XCode 4 模板“实用程序应用程序”,具有 MainView 和 MainView。 FlipSideView 控制器(即 MainView 不使用 UINavigationController,但以模态方式打开 FlipSideview)
- 在翻转视图中,我有一个 UITableView,它被设置为执行配置设置
- 希望能够单击此 FlipSideview UITableView 的一行,然后使用UINavigationController 概念,然后水平转换到以编程方式生成的 UITableView,以便用户可以选择/更改值,完成后他们可以单击顶部的“后退”按钮left(UINavigationController 将提供)
- Re XIB 文件 那么总的来说,MainView 和 FlipSideView 将有一个 XIB 文件(来自模板),但以编程方式生成的“选择值”视图不会有一个
所以我实际上不确定在这种情况下,在哪里/如何创建/保留/使用 UINavigationController?这里的代码会是什么样子,UINavigationController 变量将保存在哪里,FlipSideView XIB 是否需要修改?
附言。事实上,FlipSideview 本身是否必须进行更改才能在顶部合并导航栏? (然后我必须将现有模板的“完成”按钮从导航栏模式设置为新的 UINavigationController 导航栏)
PSS。尝试这样做但出现错误:
- (void)viewDidLoad
{
[super viewDidLoad];
self.uiNavController = [[UINavigationController alloc] initWithRootViewController:self];
self.navigationController = self.uiNavController;
// ==> error: object cannot be set - either readonly property or no setter found
}
What would the code be to make use of a UINavigationController in the following circumstance?
- The base application is based on the XCode 4 template "Utility Application", has a MainView & FlipSideView controller (i.e. MainView does not use a UINavigationController, but modally opens the FlipSideview)
- In the flipside view I have a UITableView that is setup to perform configuration settings
- Want to be able to click on one row of this FlipSideview UITableView and then, using a UINavigationController concept, then transistion across horizontally to a programmatically generated UITableView so the user can select/change the value, then once finished they could click on the BACK BUTTON at the top left (which the UINavigationController would supply)
- Re XIB files then overall, the MainView and FlipSideView would have a XIB file (from the template), but the programmatically generated "select value" view wouldn't have one
So I'm not actually sure where/how to create/hold/use the UINavigationController in this case? What would the code look like here, where would the UINavigationController variable be held, would the FlipSideView XIB need to be modified?
PS. In fact would the FlipSideview itself have to change to incorporate a navigation bar at the top? (then I'd have to mode the existing template's DONE button from it's nav bar, to the new UINavigationController nav bar I guess)
PSS. Trying this but get an error:
- (void)viewDidLoad
{
[super viewDidLoad];
self.uiNavController = [[UINavigationController alloc] initWithRootViewController:self];
self.navigationController = self.uiNavController;
// ==> error: object cannot be set - either readonly property or no setter found
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您的 FlipSideViewController 本身应该实现 UINavigationControllerDelegate。
FlipSideView 的显示效果如何?
像这样????
然后你得把它改成
for this, your FlipSideViewController itself should implement UINavigationControllerDelegate.
How are showing that FlipSideView?
Like this????
Then u have u to change it to
UINavigationControllers 被设计为你的层次结构的根视图控制器。
因此,在您的示例中,您应该让 FlipSideViewController 包含一个 UINavigationController 并隐藏 NavigationBar。然后您可以将 TableViewController 作为“根”视图推送到堆栈上。
当用户点击表格视图中的单元格时,您可以实例化一个新视图并创建一个新视图。将其推送到 self.navigationController 的堆栈上。确保将代码添加到新视图的 viewWillAppear 方法中以显示导航栏和导航栏。将代码添加到 viewDidDisappear 以再次隐藏导航栏。
UINavigationControllers are designed to be the ROOT view controller of your heirarchy.
So in your example, you should have the FlipSideViewController hold a UINavigationController with the NavigationBar hidden. Then you can PUSH your TableViewController onto the stack as the 'root' view.
When a user taps a cell in your tableview, you can instantiate a new view & PUSH it onto the self.navigationController's stack. Ensure you add code to the new view's viewWillAppear method to show the navigationBar & code to the viewDidDisappear to hide the navigationBar again.