我创建了一个自定义tableviewcell。该班有3个标签。使用主视图控制器模板开始,我更改了故事板中的默认tableviewcell以引用我的新自定义单元格,我还将类型更改为自定义,并将标识符更改为“CustomTableCell”。我也修改了我的cellForRowAtIndexPath方法如下...自定义tableviewcell不显示
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"CustomTableCell";
CustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
cell = [[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
Item *currentItem = _objects[indexPath.row];
cell.nameLabel.text = [currentItem name];
cell.vegLabel.text = @"V";
return cell;
}
自定义单元格的头文件
#import <UIKit/UIKit.h>
@interface CustomTableCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic, weak) IBOutlet UILabel *vegLabel;
@property (nonatomic, weak) IBOutlet UILabel *priceLabel;
@end
Eveything似乎在我的故事板正确连接。当我调试时,我可以看到单元格具有我自定义单元格的属性。然而,当我运行应用程序的每一行都是空白的。 tableviewcell在故事板中使用正确的标识符。我只是看不到我错过了什么。任何帮助,将不胜感激。谢谢。
你有答案吗? –