繁体   English   中英

未在View Controller中加载CollectionView单元

[英]CollectionView Cells not loading in View Controller

我正在尝试通过Firebase根据用户数据在Feed中加载一些数据,但是,它无法正常工作。 我的应用程序当前已组织好,以便用户输入CustomTabBarController并经过验证可以登录,并且已经创建了配置文件,并在需要时进行检索。 然后,我通过以下方式将用户发送到供稿:

// 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是一组委托和协议,并以以下方式返回(我已验证它可以正确检索photoURL)。 然后,调试器认为此后不再有其他方法可以触发。

func feedProfilePhotosRetrieved(photoURLs: [String]) {

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

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

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”的声明中设置了一个断点,但是没有触发。

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()时也必须调用上述函数吗? 感谢您的帮助,如果您需要其他信息,请告诉我。

方法numberOfItemsInSection应该返回photoURLs.count

extension FeedViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return photoURLs.count
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM