【发布时间】:2019-04-08 19:05:59
【问题描述】:
我在将“用户选择”图像分配给 tableViewCells - 和 tableview 背景时遇到问题。我收到错误“无法分配 'UIImage 类型的值?”键入“UIView?”。
外汇。当我编写以下内容时,尝试获取用户选择的图像,显示在特定单元格中:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Diary1", for: indexPath)
cell.textLabel?.text = allDiaries[indexPath.row].diaryName
cell.detailTextLabel?.text = allDiaries[indexPath.row].diaryQuestion
cell.backgroundView = UIImage(data: newDiary?.diaryTheme ?? Data())
return cell
}
另外一个地方我在写这个时遇到同样的错误:
override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundView = UIImage(data: (newDiary?.diaryTheme ?? Data()))
}
所以我想在使用 tableView 的背景时,你必须知道如何从 UIImageView 转换为 UIView。
有人知道怎么做吗?
谢谢!
【问题讨论】:
标签: ios swift uiview uiimageview tableview