报错:Illegal Configuration: The Label outlet from the ViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.
产生原因:tableview里面的label是动态的,而用storyboard那样拖动绑定过来的outlet是静态的,所以不能采用这种方法来绑定。应该采用如下方法:
首先给label设置一个Tag,比如105
然后在代码中使用viewWithTag的方法访问:
1 2 3 4 5 6 |
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell let myLabel = cell.viewWithTag(105) as! UILabel myLabel.text = myArr[indexPath.row] return cell } |
❤ 点击这里 -> 订阅《PAT | 蓝桥 | LeetCode学习路径 & 刷题经验》by 柳婼
❤ 点击这里 -> 订阅《从放弃C语言到使用C++刷算法的简明教程》by 柳婼
❤ 点击这里 -> 订阅PAT甲级乙级、蓝桥杯、GPLT天梯赛、LeetCode题解离线版
