是的,您无法使用 ctrl+drag 方法连接自定义原型单元内的视图。而是使用视图的标签属性,然后在构建单元格时使用它们的标签拉出标签。
这里:
//Let's assume you have 3 labels. One for a name, One for a count, One for a detail
//In your storyboard give the name label tag=1, count tag=2, and detail tag=3
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *theCell = [tableView dequeueReusableCellWithIdentifier:@"Prototype Cell"];
UILabel *nameLabel = (UILabel *)[theCell viewWithTag:1];
UILabel *countLabel = (UILabel *)[theCell viewWithTag:2];
UILabel *detailLabel = (UILabel *)[theCell viewWithTag:3];
nameLabel.text = @"name";
countLabel.text = @"count";
detailLabel.text = @"details";
return theCell;
}
您还可以在自定义单元格代码中将标签设置为属性,然后在初始化单元格时使用 viewWithTag 调用将标签属性分配给您在情节提要上创建的标签。
我花了几天时间才意识到我无法从自定义单元格中按 ctrl+拖动来创建 IBOutlet。
祝你好运!
编辑:您可以在自定义单元格内为您的标签创建 IBOutlets 并以编程方式创建链接,而不是通过 ctrl+drag 方法。
编辑2:我完全错了,你可以ctrl+drag。请参阅此问题的第二个答案。这很棘手,但效果很好。