所有uitableviewcell在iOS 9上都变成一行高度 [英] All uitableviewcells become one line in height on iOS 9

查看:85
本文介绍了所有uitableviewcell在iOS 9上都变成一行高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个UITableView控制器的应用程序.在iOS 8.x上运行,每个表中所有单元格的高度将调整大小以适合单元格的内容(所有单元格仅包含带有纯文本的UILabel).现在,在iOS 9上运行时,每个表上的每个单元格只有一行高.这与动态表和静态表均相同.我已经仔细检查过UIKit差异文档并进行了广泛的搜索,但是我找不到合适的组合来获得除所有表的所有单元格中的一行高度以外的任何内容.

I have an app with several UITableView controllers. Running on iOS 8.x, the height of all the cells in each table would resize to fit the content of the cell (all contain just a UILabel with plain text). Now when running on iOS 9, every cell on every table is only one line tall. This is with both dynamic and static tables. I've scoured the UIKit diffs document and done extensive searching, but I can't find the right combination of things to get anything other than a height of one line in all the cells in all the tables.

推荐答案

我遇到了类似的情况.技巧似乎是通过UITableView的委托方法显式实现动态大小调整.即使情节提要中的设置automatic被设置为可以工作-不能.解决方案是通过委托方法显式提供UITableViewAutomaticDimension,然后像往常一样提供估计的像元大小:

I've run into a similar case. The trick seems to be to implement the dynamic sizing via UITableView's delegate methods explicitly. Even though settings automatic in storyboards is supposed to work - it doesn't. The solution is to provide UITableViewAutomaticDimension explicitly via the delegate method and then provide estimated cell sizes as you normally would:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {

    /* Return an estimated height or calculate 
     * estimated height dynamically on information 
     * that makes sense in your case.
     */
    return 200.0f;
}

如果有人确切地知道为什么,那么这在iOS 9中是必需的,它与iOS 8有何不同,我很想听听.

If anyone knows precisely why this is necessary in iOS 9 and how it differs from iOS 8, I'd love to hear it.

这篇关于所有uitableviewcell在iOS 9上都变成一行高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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