xcode 为什么我的项目中会出现三个“非法配置”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15488135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:00:30  来源:igfitidea点击:

Why am I getting three "Illegal Configuration" errors within my project?

iosobjective-cxcodeuitableview

提问by user212541

I have a project where I have three labels in a custom cell prototype class (subclass of UITableViewCell) that are linked to three label outlets in the custom cell's .h file.

我有一个项目,其中在自定义单元格原型类(UITableViewCell 的子类)中有三个标签,这些标签链接到自定义单元格的 .h 文件中的三个标签出口。

Then in my main viewcontroller class (which houses the prototype cells and is a subclass of UITableViewController) my delegate method that interacts with these labels looks like this:

然后在我的主视图控制器类(它包含原型单元并且是 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;
}

Yet I get these three errors:

然而我得到了这三个错误:

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.

What exactly am I doing wrong? I'm so confused.

我到底做错了什么?我很困惑。

回答by nsgulliver

You might be connecting the Label outlets wrong in your project. I assume that labels articleURL, articlePreviewand articleTitleare defined in the UITableViewCell. They should be connected for outlets in the corresponding customTableViewCellclass not in the UIViewController. As you are referencing self.articleTitlesin cellForRowAtIndexPath, it suggests that you are connecting them as outlets of current class not the customTableViewCellclass. It is good idea to define your customTableCell as a property to your current class which is having UITableView's Delegate implemented.

您可能在项目中错误地连接了 Label 插座。我认为唱片公司articleURLarticlePreviewarticleTitle在被定义UITableViewCell。它们应该连接到相应customTableViewCell类别中的插座,而不是UIViewController. 正如您在 中引用的self.articleTitles那样cellForRowAtIndexPath,它表明您将它们连接为当前班级而不是customTableViewCell班级的出口。最好将 customTableCell 定义为当前类的属性,该类实现了 UITableView 的 Delegate。

Have a look at TableView Programmingfor details.

有关详细信息,请查看TableView 编程