ios Xcode 错误:插座无法连接到重复内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30008166/
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-08-31 05:52:19  来源:igfitidea点击:

Xcode Error: Outlets cannot be connected to repeating content

iosxcodeuitableviewswiftmapkit

提问by Alec

After doing some searching and editing, I can't seem to find a solution to fixing this error. I'm trying to link my location search results with a table to display the search results in a list-form.

在进行了一些搜索和编辑后,我似乎找不到修复此错误的解决方案。我正在尝试将我的位置搜索结果与表格链接起来,以列表形式显示搜索结果。

I have my map with the details button linked with a UIViewController called 'FirstViewController.' My results table is linked with a UITableViewController called 'ResultsTableViewController.' My prototype cells are linked with a UITableViewCell called 'ResultsTableCell' which is also where my outlets are located.

我的地图带有与名为“FirstViewController”的 UIViewController 链接的详细信息按钮。我的结果表与一个名为“ResultsTableViewController”的 UITableViewController 相关联。我的原型单元格与一个名为“ResultsTableCell”的 UITableViewCell 链接,这也是我的插座所在的位置。

Here are the 2 separate errors:

以下是 2 个单独的错误:

Illegal Configuration: The nameLabel outlet from the ResultsTableViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.

Illegal Configuration: The phoneLabel outlet from the ResultsTableViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.

非法配置:从 ResultsTableViewController 到 UILabel 的 nameLabel 出口无效。插座不能连接到重复的内容。

非法配置:ResultsTableViewController 到 UILabel 的 phoneLabel 出口无效。插座不能连接到重复的内容。

I've read other people's posts with the same problem, tried to fix them accordingly and I'm still getting the same error.

我读过其他人的帖子有同样的问题,试图相应地修复它们,但我仍然遇到同样的错误。

Here is the code for populating the cell, located in my ResultsTableViewController.

这是用于填充单元格的代码,位于我的 ResultsTableViewController 中。

let cell = tableView.dequeueReusableCellWithIdentifier("resultCell", forIndexPath: indexPath) as! ResultsTableCell

    // Configure the cell...
    let row = indexPath.row
    let item = mapItems[row]
    cell.nameLabel.text = item.name
    cell.phoneLabel.text = item.phoneNumber
    return cell
}

The code in my ResultsTableCell class:

我的 ResultsTableCell 类中的代码:

import UIKit

class ResultsTableCell: UITableViewCell {
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var phoneLabel: UILabel!
}

回答by Leo Dabus

This message only occurs if you connect it to the view controller. As I have already commented, you probably did not delete the first connection outlet you've made to your view controller. Even if you delete the IBOutlet code from your view controller you still need to right click it and delete the old connection that probably still there. After deleting it the error message will go away.

仅当您将其连接到视图控制器时才会出现此消息。正如我已经评论过的,您可能没有删除您对视图控制器所做的第一个连接出口。即使您从视图控制器中删除了 IBOutlet 代码,您仍然需要右键单击它并删除可能仍然存在的旧连接。删除它后,错误消息将消失。

回答by Mina Fawzy

this issue happen when you delete view from your class but still have reference in your view

当您从班级中删除视图但在您的视图中仍然有参考时会发生此问题

here is example I remove back outlet reference from my class but my view still keep the reference Notice yellow rectanglejust delete it by click at x

这是示例我从我的班级中删除了后插座引用,但我的视图仍然保留引用注意黄色矩形只需通过单击 x 将其删除

if you want to know how to reach this view , open your storyboard , right click at top left yellow it will show this dialog

如果你想知道如何到达这个视图,打开你的故事板,右击左上角的黄色它会显示这个对话框

enter image description here

在此处输入图片说明