屏幕上未显示CollectionView单元

时间:2019-06-30 16:15:36

标签: ios swift collections uicollectionview uicollectionviewcell

这是我第二次处理集合视图,我似乎无法让我的单元格显示在屏幕上。我尝试了多种不同的方式,例如注册单元格,但仍然无法显示单元格,并且出现错误:“线程1:信号SIGABRT”我之前曾尝试过此类错误,但这次我无法弄清楚我做错了什么。有人可以帮帮我吗?任何答案将不胜感激。

  

由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法在捆绑包中加载NIB:'NSBundle

如果需要,这是我的视图控制器代码:

import Foundation
import UIKit
class HomeViewController: UIViewController{

override func viewDidLoad(){
    super.viewDidLoad()



}

var eventTitle = ""
var dueDate = ""
var datePosted = ""
var eventDescription = ""

@IBOutlet weak var viewAllThingsToDo: UIButton!

@IBOutlet weak var viewAllGetItDone: UIButton!

@IBAction func viewAllThingsToDoAction(_ sender: Any) {

    func TtdButtonPressed (dueDate: Date, title: String, datePosted: Date, Description: String?) {


    }

}
@IBOutlet weak var GIDCollectionView: ThingsToDoCollectionView!

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "homeToDetailedEvents" {
        let destVc = segue.destination as! DetailedEventsViewController
        destVc.eventTitle = eventTitle
        destVc.dueDate = dueDate
        destVc.datePosted = datePosted
        destVc.eventDescription = eventDescription
    }
}
@IBAction func viewAllGetItDoneAction(_ sender: Any) {

}







}


extension HomeViewController: UICollectionViewDataSource {


func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 1
}

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


    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ThingsToDoCollectionViewCell", for: indexPath)

    if let myCVC = cell as? ThingsToDoCollectionViewCell {

        if myCVC.GIDTitle != nil {
            myCVC.GIDTitle?.text = "Title"
            print("1Contains a value!")
        } else {
            print("1Doesn’t contain a value.")

        }

        if myCVC.GIDDueDate != nil {
            myCVC.GIDDueDate?.text = "June 17"
            print("2Contains a value!")
        } else {
            print("2Doesn’t contain a value.")

        }
        if myCVC.GIDThumbnail != nil {
            myCVC.GIDThumbnail?.image = UIImage(named: "IMG_7070")
            print("3Contains a value!")
        } else {
            print("3Doesn’t contain a value.")
        }

    }
    return cell
}

func numberOfSections(in collectionView: UICollectionView) -> Int {
    return 1
}

}

extension HomeViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print(indexPath)
}
}

这是我的收藏夹视图单元格的代码:

import UIKit

class ThingsToDoCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var GIDThumbnail: UIImageView!
@IBOutlet weak var GIDTitle: UILabel!
@IBOutlet weak var GIDDueDate: UILabel!

override var isSelected: Bool {
    didSet {
        layer.borderWidth = isSelected ? 1.0 : 0.0
    }
}

}

1 个答案:

答案 0 :(得分:0)

也许在viewDidLoad中collectionview.delegate = selfcollectionview.dataSource = self