【发布时间】:2013-03-18 22:26:29
【问题描述】:
我有一个项目,其中我在自定义单元格原型类(UITableViewCell 的子类)中有三个标签,它们链接到自定义单元格的 .h 文件中的三个标签出口。
然后在我的主视图控制器类(它包含原型单元并且是 UITableViewController 的子类)中,与这些标签交互的委托方法如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ArticleCell";
ArticleCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
int row = indexPath.row;
cell.articleTitle.text = self.articleTitles[row];
cell.articleURL.text = self.articleURLs[row];
cell.articlePreview.text = self.articleURLs[row];
return cell;
}
但我得到这三个错误:
Connection "articleURL" cannot have a prototype object as its destination.
Connection "articlePreview" cannot have a prototype object as its destination.
Connection "articleTitle" cannot have a prototype object as its destination.
我到底做错了什么?我很困惑。
【问题讨论】:
-
这正是错误消息告诉您的内容。您不能将 UITableViewController 的属性链接到单元格中的视图。这是因为一次可能有多个单元实例。 (框架不会知道你是否只计划一个)。将视图连接到自定义 UITableViewCell 子类中的出口,该子类可能将 TableView 或 TableViewController 作为委托,并通过调用控制器中的方法来传递信息。听起来很复杂,但相当直接。虽然,我也不喜欢。 :)
标签: ios objective-c xcode uitableview