2014-11-21 57 views
4

我在故事板中创建了一个tableview,并创建了一个自定义原型单元格。我已经在故事板中设置了单元格标识符,并试图将其退出并且正在获取:如何连接故事板中的原型单元格?

无法使标识符TTEntry出列单元 - 必须为该标识符注册一个nib或类,或者将原型单元格连接到一个故事板

我看不到任何其他故事板TableCell属性来链接它。我只是不知道信息的内容。

有人能指出我正确的方向吗?

谢谢!

Screwtape。

+0

我们可以看到使单元出列的代码吗? – cdstamper 2014-11-21 16:46:19

回答

2

添加您CustomCell类在你的故事板

enter image description here

+0

我已经这样做了,但无济于事。 – Screwtape 2014-11-22 08:20:21

1

您应该能够:1)添加CustomCell类由Jignesh提到的,或2)的UITableViewController的viewDidLoad编程方式注册笔尖:

let nib = UINib(nibName: "yourCellIdentifier", bundle: nil) 
self.tableView.register(nib, forCellReuseIdentifier:"yourCellIdentifier") 
+0

谢谢!我试过这段代码 - 将代码转换为目标C,但仍然收到相同的错误消息。 'UINib * nib = [UINib nibWithNibName:@“TTEntry”bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:@“TTEntry”]; ' – Screwtape 2014-11-22 08:25:32

+0

你把这段代码放在viewDidLoad中(或者在调用这个标识符的单元出队前的其他地方)吗? – 2014-11-24 17:33:45

10

从故事板:

  1. 在属性检查器中设置复用标识符
  2. 添加您CustomCell类在你的故事板一样由Jignesh Agola

从代码(如酸柠檬柚贴)提到:

[self.tableView registerClass:<Your UITableViewCell subclass> forCellReuseIdentifier:<Your identifier>] 
+0

您错过了将单元出列到您的自定义类时的一个步骤 guard let cell = tableView.dequeueReusableCell(withIdentifier:kCellReuseId,for:indexPath)as? YouCustomCellClass – hariszaman 2018-02-16 14:50:30

0

如果您正在使用搜索显示控制器

[self.searchDisplayController.searchResultsTableView registerClass:[YourClass class] forCellReuseIdentifier:@"yourCellIdentifier"]; 
相关问题