首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >视图控制器中未加载CollectionView单元格

视图控制器中未加载CollectionView单元格
EN

Stack Overflow用户
提问于 2019-06-12 03:09:44
回答 1查看 562关注 0票数 1

我试图通过Firebase加载基于用户数据的提要中的一些数据,但是,它不起作用。我的应用程序当前已被组织,以便用户在CustomTabBarController上输入,并验证是否可以登录,以及是否已创建配置文件,并在需要时检索它。然后,我通过以下命令将用户发送到提要:

代码语言:javascript
复制
// Go to home feed
        let navController = self.viewControllers![0] as? UINavigationController
        let feedVC = navController?.topViewController as? FeedViewController
        if feedVC != nil {
            feedVC!.getProfilePhotos()
        }

我的第一个问题-这是在CustomTabBarController上加载FeedViewController的正确方式吗?我还会提前打电话来获取配置文件数据。

getProfilePhotos是一组委托和协议,并以以下方式返回(我已经验证它正确地检索了照片way )。然后,调试器认为在此之后没有更多的方法可激发。

代码语言:javascript
复制
func feedProfilePhotosRetrieved(photoURLs: [String]) {

    // Set photos array and reload the tableview
    self.photoURLs = photoURLs
    cardCollectionView.reloadData()
}

这是我的FeedViewController类,它的属性和viewDidLoad()/viewDidAppear()

代码语言:javascript
复制
var feedModel = FeedViewModel()
var associates = UserProfile.shared().associates
var photoURLs = [String]()

@IBOutlet weak var cardCollectionView: UICollectionView!


override func viewDidLoad() {
    super.viewDidLoad()
    associates = UserProfile.shared().associates
    feedModel.delegate = self
    cardCollectionView.delegate = self
    cardCollectionView.dataSource = self
    cardCollectionView.register(CardCollectionViewCell.self, forCellWithReuseIdentifier: "sectionCell")
    cardCollectionView.reloadData()
}

override func viewWillAppear(_ animated: Bool) {
    getProfilePhotos()
}

这是我在集合视图中创建单元格的位置。我在"cell“的声明处设置了一个断点,但它没有触发。

代码语言:javascript
复制
extension FeedViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return associates.count
}

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

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sectionCell", for: indexPath) as! CardCollectionViewCell
    let card = UserProfile.shared().associates[indexPath.row]
    cell.name.text = card.name
    cell.poscomp.text = card.title + ", " + card.company

    // Photo that we're trying to display
    let p = photoURLs[indexPath.row]

    // Display photo
    cell.downloadPhoto(p)
    cell.layer.transform = animateCell(cellFrame: cell.frame)
    return cell
} }

我是否遗漏了任何明显可见的错误?当我调用reloadingData()的时候,我也需要调用上面的函数吗?感谢您的帮助,如果您需要更多信息,请告诉我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-12 12:09:37

方法numberOfItemsInSection应返回photoURLs.count

代码语言:javascript
复制
extension FeedViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return photoURLs.count
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56550336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档