设置嵌套的collectionview单元格数等于数组

时间:2017-08-01 00:42:31

标签: ios swift uicollectionview nsarray uicollectionviewcell

我有一个嵌套在集合视图单元格内的集合视图,我需要该集合视图中的单元格数量等于超级单元格所携带的字典值。

重申一下,每个单元格都是一个房间对象,包含一个标题,一个描述和一组成员。我希望members.count等于该指定索引的内部集合视图中的单元格数。

它最初认为最好在超级单元格cellForItemAtIndexPath函数中设置它,如下所示,

if section == 0 {

    cell = liveCell

//  these work fine

    let room = rooms[indexPath.row]
    liveCell.liveStreamNameLabel.text = room.groupChatName
    liveCell.descriptionLabel.text = room.groupChatDescription

//  this does not
    liveCell.profileCV.numberOfItems(inSection: 0) = room.members?.count

    return cell

}

但似乎numberOfItems(inSection: )是一种get方法。

我尝试在实际内部集合视图numberOfItemsInSection函数中访问数组计数,但每次都返回零。

lazy var homeController: HomeController = {
    let hc = HomeController()
    hc.liveCell = self
    return hc
}()

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

//    does not work
//    let room = homeController.rooms[indexPath.row]
//    return homeController.room.count

//  doesn't crash but returns zero everytime
    return homeController.rooms.count
}

有什么建议吗?

0 个答案:

没有答案
相关问题