如何在 TableViewController 上方添加 UIView [英] How do I add an UIView above a TableViewController
问题描述
我想在我的 tableview 上方显示一个 UIView,出于测试目的,我使用了一个搜索栏(以消除我的代码可能出现的任何问题).
I would like to display an UIView above my tableview, for testing purposes I have used a Searchbar (to eliminate any possible problems with my code).
我的设置:
标签栏控制器
MyCustomTableViewController
查看
TableView(用于自定义单元格高度)
搜索栏
My setup:
Tab bar controller
MyCustomTableViewController
View
TableView (for customizing cell height)
Searchbar
我已将搜索栏定位在窗口"的顶部并下拉tableview,使其直接位于搜索栏下方.
所以在 IB 中,一切看起来都很棒.
但是当我启动应用程序时,tableview 占据了整个屏幕,而搜索栏却无处可寻.
I have positioned the searchbar at the top of the "window" and pulled down the tableview so that it is positioned directly below the searchbar.
So in IB everything looks great.
But when I start the application the tableview takes up the whole screen, and the searchbar is nowhere to be found.
我对 iPhone 开发很陌生,所以可能有一个非常简单的解决方案(?).
/吉米
I'm quite new to IPhone development so there might be a very simple solution(?).
/Jimmy
推荐答案
真正简单的解决方案是:
The really simple solution is to:
- 创建一个自定义的 UIViewController 子类,它实现了
UITableViewDelegate
和UITableViewDataSource
,就像UITableViewController
一样.还要添加一个UITableView
插座. - 在 XIB 文件中,将您的搜索栏和
UITableView
放在视图控制器的视图中. - 将表格视图连接到自定义
UIViewController
中的 - 将
UITableView
的委托和数据源连接到文件的所有者(实现正确委托的自定义UIViewController
)
tableView
插座- Create a custom UIViewController subclass that implements
UITableViewDelegate
andUITableViewDataSource
just likeUITableViewController
does. Also add aUITableView
outlet. - In the XIB file, put your searchbar and
UITableView
inside the view controller's view. - Connect the table view to the
tableView
outlet in your customUIViewController
- Connect the
UITableView
's delegate and datasource to the File's Owner (your customUIViewController
that implements the right delegates)
您现在拥有一个自定义视图控制器,它的工作方式与 UITableViewController
类似,但您可以完全控制它的布局.您以相同的方式实现委托.
You now have a custom view controller that works just like a UITableViewController
except you have total control over it's layout. You implement the delegates in the same way.
这篇关于如何在 TableViewController 上方添加 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!