ios - 在表视图的自定义单元格上隐式展开可选值时意外发现 nil
问题描述
我正在尝试从数组中在 tableview 上创建一个自定义单元格。当我在我的自定义单元格上附加任何文件时,我在所有文件上都得到了意想不到的零,我不知道为什么
这是我的自定义单元格:
class CustomMovieCell: UITableViewCell {
@IBOutlet weak var title: UILabel!
@IBOutlet weak var rating: UILabel!
@IBOutlet weak var releaseYear: UILabel!
@IBOutlet weak var genre: UILabel!
var imageBackground: String!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
这是我的 tableview cellForRowAtIndexPath 方法:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MovieCell", for: indexPath) as! CustomMovieCell
let movieFetched = Movie(title: moviesArray[indexPath.row].title, image: moviesArray[indexPath.row].image, rating: moviesArray[indexPath.row].rating, releaseYear: moviesArray[indexPath.row].releaseYear, genre: moviesArray[indexPath.row].genre)
print(movieFetched)
cell.title.text? = movieFetched.title
cell.rating.text? = String(movieFetched.rating)
cell.releaseYear.text? = String(movieFetched.releaseYear)
cell.genre.text? = String(movieFetched.genre[0])
return cell
}
我错过了什么?当附加任何文件时,我在展开可选值时意外发现 nil - 我不知道 UIlabel 因为 IBOutlet 是可选的?尽管它们在我的自定义单元类中不是可选的。
解决方案
推荐阅读
- python - 保存 9GB 数据帧时出现 Pickle 内存错误
- c# - 如何在 Azure API 函数中返回变量并通过移动应用程序中的 InvokeApiAsync 函数读取它
- java - 如何从另一个类更改框架的大小
- c++11 - 如何使用 make_shared 创建相同类型的对象数组?
- php - 如何在php中的url中抑制给定特定字符串的短代码
- regex - 考虑到特殊的正则表达式,如何正确使用 sed 替换命令的反向引用
- progressive-web-apps - 事件触发时如何打开 pwa(添加到主屏幕)?
- c++ - clang 格式的 K&R 大括号样式
- google-cloud-platform - Google Cloud App:错误:(gcloud.app.deploy)INVALID_ARGUMENT:任何空格都必须在文件名的中间:
- python - Randint 不会执行