首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >黑色UICollectionView

黑色UICollectionView
EN

Stack Overflow用户
提问于 2016-07-31 09:21:10
回答 1查看 101关注 0票数 0

我一直在学习如何使用UICollection视图。我创建了一个新的单元控制器,并在main.storyboard中将集合视图单元格标识为“UICollectionView”。每当我轻触UICollectionView控制器(通过TapBar控制器)时,我都会看到黑屏。我目前正在使用Firebase导入/导出数据。谢谢你的帮助!

代码语言:javascript
复制
  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
        }

    }
EN

回答 1

Stack Overflow用户

发布于 2016-08-02 04:10:01

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38679939

复制
相关文章

相似问题

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