ios - 从 VC 到 UILabel 的导出无效。 Outlet 无法连接到重复内容

标签 ios swift swift3

我正在开发一个待办事项列表应用程序,该应用程序可在 Swift 中使用表格 View 。 TableView 有一个名为 titleLabelOutlet 的 UILabel 。当我构建应用程序时,我收到一条错误消息 The titleLabelOutlet outlet from the FirstViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.我以前从未收到过此错误。我如何解决它?这是我的代码:

import UIKit

var phoneNumberList = [String]()
var titleFieldList = [String]()
class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var titleLabelOutlet: UILabel!
@IBOutlet weak var phoneNumberLabelOutlet: UILabel!

@IBOutlet weak var myTableView: UITableView!

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return (phoneNumberList.count)
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
    phoneNumberLabelOutlet.text = phoneNumberList[indexPath.row]
    titleLabelOutlet.text = titleFieldList[indexPath.row]

    return(cell)
}

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
    if editingStyle == UITableViewCellEditingStyle.delete
    {
        phoneNumberList.remove(at: indexPath.row)
        titleFieldList.remove(at: indexPath.row)
        myTableView.reloadData()
    }
}

override func viewDidAppear(_ animated: Bool) {
    myTableView.reloadData()
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

error image

最佳答案

您的 socket 应该位于单元类而不是 View Controller 中,因为标签位于单元格内 在 crllfor row at delegate 中,您必须像那样获得 socket `let cell = tableView.dequeueReusableCell(withReuseIdentifier: cellIdentifier", for: indexPath) as!TableViewCellClass

            cell.lbloutlet.text = "任何文本" 返回单元格

`

关于ios - 从 VC 到 UILabel 的导出无效。 Outlet 无法连接到重复内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45469581/

相关文章:

ios - 将 UIImage 保存到 PHAssetCollection

ios - UIImageView 实时滤镜在相机预览层上拉伸(stretch)

arrays - 从值字典数组中检索键

swift - 找到两个 ImageView 重叠的重叠区域,并使该区域改变颜色

ios - Swift - 启动屏幕 SIGABRT 错误

IOS Swift 3 FCM token 生成无效 token

ios - 调用performSegueWithIdentifier后获取重复的UIViewController实例

ios - Xcode 9.2 使用 Firebase 生成警告

swift - Swift 运行时如何处理元组?

ios - 使用适用于 iOS 的 FirebaseUI 访问数据库