我是iphone开发新手。我正在使用xCode 4.2与故事板。我试图让我的tableview中的单元格显示几个uilabels。他们只是没有出现在我的模拟器中。但原来的cell.textLabel
正在出现。Custom Cell中的标签不出现
这是我所做的: 我创建了一个新的customcell.h/.m文件来扩展UITableViewCell。我在类中添加了一些实例变量。我去了故事板,在tableviewcell的身份检查员的课堂上,我将它改为指向customcell。我拖放了一些UI标签到我的新单元格中。然后我去了连接检查器,用线拖动这些“加号”图标,将我的新uilabels连接到我的实例变量。
当我运行我的模拟器时,我没有看到任何新的UI标签。我只看到cell.textLabel
的原始uilabel。我可以以编程方式获取并设置cell.mylabel1
,cell.mylabel2
等等,这些都是新标签,但是嘿只是没有出现。
Additioanl详细信息 这是我的tableForcontroller的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中创建/离队:你在故事板中设置了重用标识符吗? –
啊你很强壮,我忘了在故事板中设置cellidentifier,我忘了在我的'cellforRowatIndexPath'函数中更新它。现在工作 – John