my collectionView должен передать модель класса, чтобы DetailViewController , но когда я нажимаю на ячейку, я получаю ошибку NIL. < /p>
фатальная ошибка: неожиданно найдено NIL, в то время как неявно развернув
необязательное значение < /p>
< /blockquote>
CollectionViewController < /code> встроенный программно на abbarController < /codeStroller < /code>. < /p>
View Collection < /strong> < /p>
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return soundArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SoundCell", for: indexPath) as? SoundCell {
let SoundClass = soundArray[indexPath.row]
cell.updateUI(SoundClass: SoundClass)
return cell
} else {
return UICollectionViewCell()
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "seguetosound", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "seguetosound" {
if let detailVC = segue.destination as? DetailSecondVC
let sound = sender as? SoundClass {
detailVC.SoundClass = sound
}
}
< /code>
Controller Controller < /strong> < /p>
class DetailSecondVC: UIViewController, UIWebViewDelegate {
private var _SoundClass: SoundClass!
var SoundClass: SoundClass {
get {
return _SoundClass
} set {
_SoundClass = newValue
}
}
< /code>
Вы знаете, что мне здесь не хватает? Я протестировал Segue с простым белым экраном, и он работает, но когда я пытаюсь передавать данные, он терпит неудачу.
Подробнее здесь: https://stackoverflow.com/questions/563 ... in-swift-4