意外发现nil,同时在表视图的自定义单元格上隐式展开一个Optional值

时间:2019-04-25 18:58:28

标签: ios swift uitableview null optional-values

我正在尝试从数组的tableview创建一个自定义单元格。 当我在自定义单元格上附加任何文件时,我在所有文件上都得到了意外的nil,我也不知道为什么

这是我的自定义单元格:


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

    }

我想念什么?当附加任何文件时,我在打开可选值时意外发现为零-我不知道UIlabel作为IBOutlet是可选的吗?即使在我的自定义单元格类中它们不是可选的。

0 个答案:

没有答案