问题描述
我正在尝试使用新的Storyboard设计器以及绘制UITableView单元格的简易性,而不是以编程方式设计每一行。
I'm trying to make use of the new Storyboard designer and the ease of drawing UITableView cells instead of programmatically "designing" each row.
一个很好的例子堆栈溢出时标准单元格链接在此处:
A good example of a standard cell is linked here at stack overflow:iPhone - dequeueReusableCellWithIdentifier usage
我想在每行的顶部使用我自己的标签,按钮和图像,而不是使用[cell textLabel]的链接方法。
因此我创建了几个原型单元格/行并为它们分配了标识符(使用Storyboard)。
Instead of the linked approach of using "[cell textLabel]" I want to use my own labels, buttons and images on top of each row.Therefore I created several prototype cells/rows and assigned identifiers to them (using Storyboard).
现在:访问每一行的最自定义的最智能方法是什么控件/标签?我试图通过ID搜索访问它们,但没有找到任何东西。
我的想法是它应该按照以下方式工作:
Now: what is the smartest way of accessing each row's "custom" controls/labels? I tried searching for accessing them by ID, but didn't find anything.My thinking was it should work along this lines:
[[[cell subviews] getObjectByID:@"labelTime"] setText:@"Whatever"];
我对API的期望是完全错误还是我没找到合适的API呢?
Is my expectation of the APIs completely wrong or didn't I just find the right API, yet?
任何想法或建议?
推荐答案
对于每个新的自定义UITableViewCell您在storyboard中创建的,您将需要创建一个新的类文件,该文件实现UITableViewCell以将其链接到。确保将您在storyboard中布局的新单元格中的所有控件映射到实例属性。然后你就可以像往常一样使用它出列:
For each new custom UITableViewCell that you create in storyboard, you will want to create a new class file which implements UITableViewCell to link it to. Be sure to map all of the controls within your new cell that you laid out in storyboard to instance properties. Then you'll just use it with dequeuing like normal:
YourTableViewCellClass *cell = (YourTableViewCellClass*)[tableView dequeueReusableCellWithIdentifier:@"YourCellIdentifierStringDefinedInStoryBoard"];
// then set the properties for the class.
cell.labelTime = @"whatever";
这篇关于iPhone-如何将Storyboard与自定义UITableView单元格和CellWithIdentifier一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!