我有一个连接到表视图的tableviewcontroller。我想在表视图中有一个自定义单元格类型。自定义单元格应该有三个UILabels
和一个UIImageView
。
我在故事板中设计了tableview中的自定义单元格(使用原型单元格)。我创建了一个UITableViewCell
的子类,并将原型单元格链接到这个类。我还将单元格的重用标识符设置为" ItemCell"。
在UITableView
我有一个添加按钮。当我按下此按钮时,应将新单元格(自定义单元格)添加到tableview中。他们是(我可以通过我可以选择它们的事实来判断)除了它们是空白的(尽管标签应该显示一些东西)。标签作为UITableViewCell
属性连接到IBOutlet
子类,并且具有灰色背景,因此我可以看到它的框架,但我看到的只是一个白色的行。
出了什么问题?
这是viewDidLoad
中的UITableViewController
方法。
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[ItemCell class] forCellReuseIdentifier:@"ItemCell"];
self.navigationItem.title = @"Home";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addNewItem:)];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
这是cellForRowAtIndexPath:
方法的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemCell" forIndexPath:indexPath];
cell.nameLabel.text = @"hello";
return cell;
}
答案 0 :(得分:1)
如果您正在使用原型单元格,则在故事板中指定重用标识符,并从中解压缩单元格。通过调用此代码:
[self.tableView registerClass:[ItemCell class] forCellReuseIdentifier:@"ItemCell"];
您正在删除该注册并将其替换为ItemCell
类的简单空实例,因此不会有子视图和没有填充的插件。
删除要修复的代码行。