gpt4 book ai didi

ios - 黑色 UICollectionView

转载 作者:行者123 更新时间:2023-11-30 13:11:27 29 4
gpt4 key购买 nike

我一直在学习如何使用 UICollection View 。我制作了一个新的 UICollectionView Controller ,并将 collectionview 单元格标识为 main.storyboard 中的“Cell”。每当我点击 UICollectionView Controller (通过 TapBar Controller )时,我都会遇到黑屏,我当前正在使用 Firebase 导入/导出数据。感谢您的帮助!

  class UserCollectionViewController: UICollectionViewController {
var databaseRef = FIRDatabase.database().reference()
var usersDict = NSDictionary?()

var userNameArray = [String]()
var userImageArray = [String]()

override func viewDidLoad() {
super.viewDidLoad()


self.databaseRef.child("user_profile").observeEventType(.Value, withBlock :{
(snapshot) in
self.usersDict = snapshot.value as? NSDictionary
for(userId,details) in self.usersDict! {
let img = details.objectForKey("profile_pic_small") as! String
let name = details.objectForKey("name") as! String
let firstName = name.componentsSeparatedByString(" ")[0]
self.userImageArray.append(img)
self.userNameArray.append(firstName)
self.collectionView?.reloadData()
}


})

}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.userImageArray.count
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CollectionViewCell
return cell


let imageUrl = NSURL(string: userImageArray[indexPath.row])
let imageData = NSData(contentsOfURL: imageUrl!)

cell.userImage.image = UIImage(data: imageData!)
cell.userName.text = userNameArray[indexPath.row]

return cell
}

}

最佳答案

在单元格中放置一个 UIView(将其约束设置为相对于单元格的 0,0,0,0),然后向其中添加 imageView 和标签。另外不要忘记确认委托(delegate)和数据源。

关于ios - 黑色 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38679939/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com