良い一日!それは私が怒っている、 '私は何が起こっているのか分からないからです。
私は類似のロジックを持つ2つのTableViewControllerを持っています。
私は1データモデルで作業します。
このモデルにはユーザー情報が含まれており、各エンティティには常に写真があります。デバッグpartners[indexPath.item].userPhoto
で実際のデータを持つUIImage initはnilを返す
var partnerPhoto: UIImage? = nil
if let imageData = partners[indexPath.item].userPhoto {
partnerPhoto = UIImage(data: imageData as! Data)
}
は、実際のデータを持っているとさえimageData
が4213のバイトを示しています
は、それを初期化するために、私は以下のコードを使用します。一般的なエラーと
しかし、アプリのクラッシュ:
fatal error: unexpectedly found nil while unwrapping an Optional value
EDIT:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if dialogs[indexPath.item].fromID == profileID {
let cell = tableView.dequeueReusableCell(withIdentifier: "dialogMeCell", for: indexPath) as! CellForDialogMe
var partnerPhoto: UIImage? = nil
if let imageData = partners[indexPath.item].userPhoto {
partnerPhoto = UIImage(data: imageData as! Data)
}
cell.fillWithContent(partnerPhoto: partnerPhoto!, selfPhoto: profilePhoto!)
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "dialogHimCell", for: indexPath) as! CellForDialogHim
var partnerPhoto: UIImage? = nil
if let imageData = partners[indexPath.item].userPhoto {
partnerPhoto = UIImage(data: imageData as! Data)
}
cell.fillWithContent(partnerPhoto: partnerPhoto!)
return cell
}
SOLUTION:私はこの問題の具体的な解決策を見つけていない事実 、私は見ることのモデルからいくつかのロジックを移動しましたコントローラ。モデルではURLからデータにロードしました。今私はViewControllerでそれを正しく実行し、それは完璧に動作しますが、奇妙な、私にとっては非常に奇妙です、 '私はちょうどcmd-x cmd-vでした。
エラーの原因となるのは、どのラインですか? – rmaddy
そしてなぜ 'imageData'を強制的にキャストするのですか? 'if let'行でキャストを行います。 – rmaddy