UITableViewCell的contentView的宽度与给定的附件类型 [英] UITableViewCell's contentView's width with a given accessory type

查看:510
本文介绍了UITableViewCell的contentView的宽度与给定的附件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone上,当显示特定附件视图(公开指示符等)时,如何计算表格视图单元格的内容视图的宽度?

On an iPhone, how do you figure out the width of a table view cell's content view when it is showing a certain accessory view (disclosure indicator, etc)?

我需要这个为了计算包含包装,可变长度文本的单元格的正确单元格高度。但是当表视图委托被要求一个单元格高度时,它实际上没有实际的单元格实例,因此它不能直接查询内容视图边界。

I need this in order to calculate the correct cell height for cells that contain wrapping, variable-length text. But when the table view delegate is asked for a cell height, it doesn't actually have the actual cell instance, so it can't just query the content view bounds directly.

我可以轻松地硬编码一个20像素的边缘在右边,似乎是一个平面样式表视图的纵向方向与公开指示器,但更喜欢做正确的方式,使它保持工作如果苹果决定调整保证金。

I can easily hard-code a 20-pixel margin on the right which appears to be accurate for a plain style table view in portrait orientation with a disclosure indicator, but would prefer to do it the Right Way so that it keeps working if Apple decides to tweak the margin.

(这与这个问题。)

推荐答案

就个人而言,我只是硬编码的值 -

Personally, I would just hard code the values -- simpler and things will break in a predictable way.

但是我要以编程方式做,我会创建一个UITableViewCell,设置你需要测量的编辑属性/附件视图,然后问它contentView是多大。

But were I to do this programmatically, I would create a UITableViewCell, set up the editing properties / accessory views you need to measure, and then ask it how big its contentView is.

当然,我可能会大量缓存这 - 做分配时,请求UITableView要求你的高度信息听起来像我一样是慢的(首先检查profiler,虽然,一如既往)。

Of course I would probably heavily cache this -- doing allocations when asking UITableView asks you for height information sounds to me like it would be slow (check with a profiler first though, as always).

这篇关于UITableViewCell的contentView的宽度与给定的附件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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