如何刷新UITableViewCell? [英] How to refresh UITableViewCell?

查看:61
本文介绍了如何刷新UITableViewCell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView与自定义UITableViewCell。在cellForRowAtIndexPath中,我为每个单元格中的标签分配一个字体,因为用户可以随时更改字体大小。要更改字体大小,用户可以点击表格视图下方的按钮,使用设置停用其他视图。一旦他们选择了字体大小并点击完成,该视图就会消失,并再次显示tableview。我每个查看区域显示一个单元格。因此,用户在滚动到下一个单元格之前看不到字体更改。当前单元格是我要更新的单元格。

I have a UITableView with a custom UITableViewCell. In cellForRowAtIndexPath, I assign a font to a label in every cell, since the user can change font size at any time. To change font size, the user clicks a button below the tableview, which dislays another view with settings. Once they have chosen a font size and click done, that view goes away and the tableview displays again. I display one cell per viewing area. So the user doesn't see the font change until he scrolls to the next cell. The current cell is the one I'd like to update.

我已经从设置屏幕尝试了reloadData,但是没有工作。 tableview是一个UITableViewController,但是viewWillAppear从设置屏幕消失时不会触发。我已经尝试使自定义单元格的一个属性的tableview,所以它可以从设置视图访问,然后调用setNeedsDisplay和setNeedsLayout。那些也没有工作。任何建议?

I've tried reloadData from the settings screen but that didn't work. The tableview is a UITableViewController but viewWillAppear never fires once the settings screen goes away. I've tried making the custom cell a property of the tableview so it can be accessed from the settings view, then called setNeedsDisplay and setNeedsLayout. Those didn't work either. Any suggestions?

推荐答案

对于仍然存在的单元格,必须更新标签的字体。您需要一种方法来访问自定义单元格中的自定义标签。

For the cells that are still there you have to update the font of the label. You'll need a way to access the custom label in your custom cell.

更改字体大小后,执行以下操作:

After changing the font size do something like:

for (MyCell* cell in [theTableView visibleCells]) {
    [cell.myLabel.font = newFont];
}

这篇关于如何刷新UITableViewCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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