以编程方式将NavigationBar添加到UITableViewController吗? [英] Adding a NavigationBar to UITableViewController programmatically?

查看:78
本文介绍了以编程方式将NavigationBar添加到UITableViewController吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将uitableviewcontroller创建为模态Viewcontroller,以编辑某些设置.我正在用代码创建tableviewcontroller,而我目前正苦苦挣扎的事情是如何正确地向控制器添加导航栏,该导航栏上将具有"Done"按钮:

I am trying to create a uitableviewcontroller as a modal viewcontroller to edit some settings. I am creating the tableviewcontroller in code and the thing i am struggling with currently is how to correctly add a navigation bar to the controller which will have a "Done" button on it that:

a)不会出现在表格视图的顶部,并且 b)不与表格视图一起滚动??

a) doesnt appear on top of the tableview and b) does not scroll with the tableview??

当我使用以下命令将导航栏添加到控制器时,会发生这种情况: [self.view addSubview:navigationBar]; 这向导航器添加导航栏,该导航栏位于顶部,使表的第一行变模糊,并随视图一起滚动?

This happens when i add the navbar to the contoller with: [self.view addSubview:navigationBar]; This adds a navbar to the controller which goes on top and obscures the tables first row and also scrolls with the view?

我还考虑过简单地将uiviewcontroller与单独的tableview一起使用,但是我喜欢在编辑tableviewcontroller给您的文本字段时自动滚动tableview的功能.只是不知道如何设置此导航栏?

I also thought about simply using a uiviewcontroller with a separate tableview however i like the funcitonality of automatically scrolling the tableview when editing a textfield that the tableviewcontroller gives you. Just cant figure how to setup this navbar??

thx

推荐答案

只需将UINavigationcontroller创建为模式视图控制器,然后将tableview添加为其根视图控制器.

Just create UINavigationcontroller as the modal viewcontroller, and add the tableview as its root view controller.

这篇关于以编程方式将NavigationBar添加到UITableViewController吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆