【发布时间】:2012-05-21 22:05:01
【问题描述】:
我是 iphone 开发新手。我正在使用带有情节提要的 xCode 4.2。我试图让我的表格视图中的单元格显示几个 uilabels。他们只是没有出现在我的模拟器中。但原来的cell.textLabel 出现了。
这就是我所做的: 我创建了一个扩展 UITableViewCell 的新 customcell.h/.m 文件。我在类中添加了一些实例变量。我去了情节提要,在 tableviewcell 的身份检查器类中,我将其更改为指向 customcell。我将一些 UIlabels 拖放到我的新单元格中。然后我去连接检查器拖动那些带有线条的“加号”图标以连接到我的新 uilabels 到我的实例变量。
当我运行模拟器时,我看不到任何新的 ui 标签。我只看到cell.textLabel 的原始uilabel。我可以以编程方式获取和设置cell.mylabel1、cell.mylabel2 等...,它们是新标签,但它们只是没有出现。
其他详情 这是我的 tableviewcontroller 的 cellForRowAtIndexpath 函数。
static NSString *CellIdentifier = @"Cell"; // this was the error, i needed to change this to CustomCell, or whatever it is in my storyboard
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.mylabel1.text = @"hello"; // doesn't appear in simulator
cell.textLabel.text = @"world"; // does apepar in the simulator
【问题讨论】:
-
您如何在
cellForRowAtIndexPath:中创建/出列单元格?您是否在情节提要中设置了重用标识符? -
啊,你是对的,我忘了在情节提要中设置单元标识符,我忘了在我的
cellforRowatIndexPath函数中更新它。现在工作