我正在开发一个待办事项列表应用程序,该应用程序可在 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.
}
}
最佳答案
您的 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/