[英]Send message to UITableViewCell from UITableViewController
I have designed a table view in my storyboard that uses many interface elements. 我在情节提要中设计了一个使用许多界面元素的表格视图。 For example, I have a cell with a
UIStepper
in it, and a cell that segues to another modal view. 例如,我有一个带有
UIStepper
的单元格,以及一个可以选择另一个模式视图的单元格。 It contains static cells, as it is a simple data entry form and creating new UITableViewCell
objects for each field would be a waste of time. 它包含静态单元格,因为它是一种简单的数据输入形式,并且为每个字段创建新的
UITableViewCell
对象将浪费时间。 However, I am using one custom cell from another point in the program. 但是,我正在从程序的另一点使用一个自定义单元格。 I have assigned the cell to be an instance of my custom
UITableViewCell
class, and have set the label and image view from the code (the custom cell is basic; two UILabels
and a UIImageView
). 我已将单元格分配为自定义
UITableViewCell
类的实例,并已从代码中设置了标签和图像视图(自定义单元格是基本的;两个UILabels
和一个UIImageView
)。 I set a placeholder image in the viewWillAppear
method. 我在
viewWillAppear
方法中设置了一个占位符图像。 The cell displays fine at first, however, when I change the label's text or the image in the code, the cell does not refresh until I tap it. 首先,该单元格显示正常,但是,当我在代码中更改标签的文本或图像时,直到我点击它,单元格才会刷新。 I read that using custom table view cells was the solution to this problem when it occurred with basic
UITableViewCells
, however, this does not seem to solve my problem. 我读到,使用自定义表格视图单元格是基本
UITableViewCells
出现时解决此问题的方法,但是,这似乎无法解决我的问题。 Is there a method I can declare in custom cell that reloads the cell when the data is changed? 我可以在自定义单元中声明一种方法,以在数据更改时重新加载该单元吗? If so, how?
如果是这样,怎么办?
Thanks! 谢谢!
更新了单元格后面的数据源中的信息(即图像或文本)后,应在UITableView
上调用reloadRowsAtIndexPaths:withRowAnimation:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.