调整 UITableView 的大小以适应内容
问题说明
我正在创建一个应用程序,该应用程序将在 UILabel
中有一个问题,并在 UITableView
中显示一个多项选择答案,每行显示一个多项选择.问题和答案会有所不同,所以我需要这个 UITableView
的高度是动态的.
I am creating an app which will have a question in a UILabel
and a multiple choice answers displayed in UITableView
, each row showing a multiple choice. Questions and answers will vary, so I need this UITableView
to be dynamic in height.
我想为该表找到一个 sizeToFit
解决方法.表格的框架设置为其所有内容的高度.
I would like to find a sizeToFit
work around for the table. Where the table's frame is set to the height of all it's content.
谁能建议我如何实现这一目标?
Can anyone advise on how I can achieve this?
正确答案
其实我自己找到了答案.
Actually I found the answer myself.
我只是用 table.contentSize.height
的 height
为 tableView.frame
创建一个新的 CGRect
>
I just create a new CGRect
for the tableView.frame
with the height
of table.contentSize.height
这会将 UITableView
的高度设置为其内容的 height
.由于代码修改了UI,别忘了在主线程中运行:
That sets the height of the UITableView
to the height
of its content. Since the code modifies the UI, do not forget to run it in the main thread:
dispatch_async(dispatch_get_main_queue(), ^{
//This code will run in the main thread:
CGRect frame = self.tableView.frame;
frame.size.height = self.tableView.contentSize.height;
self.tableView.frame = frame;
});
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tangbccke
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20