要解决表格视图单元格不显示相应的网站的问题,你可以尝试以下解决方法:
// 设置数据源
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomTableViewCell
let website = websiteArray[indexPath.row] // 从数据源获取网站URL
cell.websiteLabel.text = website
return cell
}
// 在自定义单元格中设置布局
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var websiteLabel: UILabel!
override func layoutSubviews() {
super.layoutSubviews()
websiteLabel.preferredMaxLayoutWidth = websiteLabel.frame.width // 设置标签的最大宽度
}
}
// 设置表格视图的高度
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60 // 设置单元格的高度
}
// 设置表格视图的代理和数据源
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
通过检查这些方面,你应该能够解决表格视图单元格未显示相应的网站的问题。