Не показывать что-либо / ошибку на моей консоли и выдавать меня Тема 1: Неустранимая ошибка: неожиданно обнаружен ноль при развертывании необязательного значения (lldb) - PullRequest
0 голосов
/ 26 марта 2020

В чем проблема не показывает никаких данных на моей консоли

//  Copyright © 2020 Arifeen Mahmud. All rights reserved.
//

import UIKit

class ViewController: UIViewController {


    @IBOutlet weak var slider: UIImageView!

    var imageNames = ["1","2","3","4","5"]//List of image names
    override func viewDidLoad() {
        super.viewDidLoad()

        myCollectionView.register(CollectionViewCell.self, forCellWithReuseIdentifier: "myCell")
        secondCollectionView.register(CollectionViewCell.self, forCellWithReuseIdentifier: "myCell")

        //        //custom collectionViewCell
        //        myCollectionView.register(UINib(nibName: "myCell", bundle: nil), forCellWithReuseIdentifier: "myCell")
        //
        //        secondCollectionView.register(UINib(nibName: "secondCell", bundle: nil), forCellWithReuseIdentifier: "secondCell")


//        //custom collectionViewCell
//        myCollectionView.register(UINib(nibName: "myCell", bundle: nil), forCellWithReuseIdentifier: "myCell")
//
//        secondCollectionView.register(UINib(nibName: "secondCell", bundle: nil), forCellWithReuseIdentifier: "secondCell")


        let timer = Timer.scheduledTimer(withTimeInterval: 1.5, repeats: true) { timer in
            self.slider.image = UIImage(named: self.imageNames.randomElement()!) //Slideshow logic
        }

        timer.fire() //Starts timer
        //timer.invalidate() //Stops timer


        myCollectionView.delegate = self
        myCollectionView.dataSource = self

        secondCollectionView.delegate = self
        secondCollectionView.dataSource = self


    }

    // MARK: Collection View Images

    @IBOutlet weak var myCollectionView: UICollectionView!

    let Imgname = ["ec","em","fn","id"]

    let mainImg:[UIImage] = [

        UIImage(named: "ec")!,
        UIImage(named: "em")!,
        UIImage(named: "fn")!,
        UIImage(named: "id")!

    ]

    @IBOutlet weak var secondCollectionView: UICollectionView!

    let secondTopic = ["ec","em","fn","id"]

    let secondImage:[UIImage] = [

        UIImage(named: "ec")!,
        UIImage(named: "em")!,
        UIImage(named: "fn")!,
        UIImage(named: "id")!

    ]

}

// MARK: Collection View
extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {



    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let width  = (view.frame.size.width - 40) / 2
        return CGSize(width: width, height: width)
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return Imgname.count
    }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        if collectionView == self.secondCollectionView {




        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "myCell", for: indexPath) as! CollectionViewCell
            cell.mainText.text = Imgname[indexPath.item]
        cell.mainImageView.image = mainImg[indexPath.item]
        return cell
    }
        else {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "secondCell", for: indexPath) as! SecondCollectionViewCell
            cell.secondText.text = Imgname[indexPath.item]
            cell.secondImage.image = mainImg[indexPath.item]
            return cell

        }

    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//        let text = mainImg[indexPath.row]
//        print("Selected \(text)")

    }
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        if segue.identifier == "DetailSegue"{
        if let dest = segue.destination as? DetailViewController,
            let index = myCollectionView.indexPathsForSelectedItems?.first {
            dest.selection = Imgname[index.row]
            }
        }
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...