UITableView使用Interface Builder中的所有可用空间 [英] UITableView uses all available space in Interface Builder

查看:112
本文介绍了UITableView使用Interface Builder中的所有可用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建UIView(在Interface Builder中)时遇到问题,该UIView包含带有其他对象的UITableView,例如UIButton或UILabel。无论UITableView对象本身的大小如何,UITableView总是占用UIView中的最大空间量。文件所有者是标准的UITableViewController。

I'm having trouble creating a UIView (in Interface Builder) that contains a UITableView with some other object, such as a UIButton or UILabel. The UITableView always takes up the maximum amount of space in the UIView, regardless of the size of the UITableView object itself. The File Owner is a standard UITableViewController.

推荐答案

以下是如何轻松完成此操作:

Here's how to do this easily:

1)使用xib创建一个表视图控制器。

1) Create a table view controller with xib.

2)将.h文件中的继承类型从UITableViewController更改为UIViewController。

2) Change the inherited type in the .h file from UITableViewController, to UIViewController.

3)将协议UITableViewDataSource,UITableViewDelegate添加到.h文件中。

3) Add the protocols UITableViewDataSource, UITableViewDelegate to the .h file.

4)打开xib,添加一个查看。

4) Open the xib, add in a view.

5)拖动视图下xib中的表格视图,根据需要调整大小。

5) drag the table view in the xib under the view, resize as desired.

6 )将文件所有者的view属性连接到View而不是UITableView。如果您希望能够重新加载或以其他方式访问表,则表视图的数据源和委托属性仍应连接到文件所有者。

6) Wire the "view" property of the File's Owner to the View instead of the UITableView. The datasource and delegate properties of the table view should still be wired to File's Owner.

7)(可选)在表视图控制器之外委托传递表视图的方法,创建名为myTable之类的UITableView * IBOutlet,然后将IB中的表连接到该表。

7) (optional) if you want to be able to reload or otherwise access the table outside of table view controller delegate methods that pass in a table view, make a UITableView * IBOutlet named "myTable" or the like, and wire the table in IB to that.

另一种方法是使用xib创建一个新的UIViewController,向xib添加一个表,将数据源/委托连接到文件的所有者,并创建一个新的UITableViewController类,用于将方法复制到视图控制器中,然后删除。

An alternate approach is to make a new UIViewController with xib, add a table to the xib, wire datasource/delegate to the file's owner, and make a new UITableViewController class which you use to copy the methods from into your view controller, then delete.

这篇关于UITableView使用Interface Builder中的所有可用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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