收集视图单元未加载

时间:2018-09-07 17:26:25

标签: ios swift uitableview uicollectionview uicollectionviewcell

我在表格视图中嵌套了一个集合视图。收集视图单元未加载。我无法在tableViewCell初始化函数中设置集合视图delgate和dataSource,因为它解开为nil,所以我创建了一个加载函数,该调用函数在单元格加载时对其进行设置。我现在遇到的问题是未调用dataSource / delgate函数,并且未加载表格视图单元格。目前,我的收藏夹视图单元只是一个图像,因此不包括在内。另外,我检查了所有这些插座的连接是否正确,并且表视图单元格和集合视图单元格都具有通过接口构建器设置的重用标识。这是我的代码:

视图控制器:

@IBOutlet weak var libraryTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.libraryTableView.dataSource = self
    self.libraryTableView.delegate = self


    // Do any additional setup after loading the view.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "LibraryTableViewCell", for: indexPath) as? LibraryTableViewCell else {
        return LibraryTableViewCell()
    }
    cell.load()
    return cell
}

表格视图单元格:

@IBOutlet weak var carouselLabel: UILabel!
@IBOutlet weak var carousel: UICollectionView!

func load() {
    layer.backgroundColor = UIColor.clear.cgColor
    carouselLabel.text = "hello world"

    carousel.delegate = self
    carousel.dataSource = self
    //carousel.reloadData()
}

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

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "packCell", for: indexPath) as? PackCollectionViewCell else {
        return PackCollectionViewCell()
    }
    return cell
}

0 个答案:

没有答案