我试图通过Firebase加载基于用户数据的提要中的一些数据,但是,它不起作用。我的应用程序当前已被组织,以便用户在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是一组委托和协议,并以以下方式返回(我已经验证它正确地检索了照片way )。然后,调试器认为在此之后没有更多的方法可激发。
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()的时候,我也需要调用上面的函数吗?感谢您的帮助,如果您需要更多信息,请告诉我。
发布于 2019-06-12 12:09:37
方法numberOfItemsInSection应返回photoURLs.count
。
extension FeedViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photoURLs.count
}
https://stackoverflow.com/questions/56550336
复制相似问题