首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView未出现在模拟器中

UICollectionView未出现在模拟器中
EN

Stack Overflow用户
提问于 2014-08-30 01:48:42
回答 1查看 1.8K关注 0票数 2

当我构建我的项目时,屏幕在模拟器中只显示为白色(集合视图为黑色),当然也不显示我想要显示的任何一个单元格。

我使用的是xcode6-beta6,这是针对ios (ipad)的。

因此,我正在尝试使用标签填充集合视图。在我的故事板中,我有一个视图控制器,里面只有一个集合视图,还有一个单元格,我在里面放了一个标签。我知道我已经在故事板和我的视图控制器代码中正确设置了标识符和标记。我知道我也正确地设置了我的dataSource和代理插座。我一直在关注本教程https://www.youtube.com/watch?v=jiiN9oFH3vE,但是它在Xcode5和objective-c中,所以我不知道在swift/xcode6中是否有一些我没有做的完全不同的东西。

以下是我的代码

代码语言:javascript
复制
import UIKit

class FirstViewController: UIViewController,UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {

    var testArray:[String]!

override func viewDidLoad() {
    super.viewDidLoad()
    testArray = ["hello","world","hola","mmg","me","la"]
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

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


func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int{
        return testArray.count
}
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!{
    var cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as FirstCollectionViewCell

    var label = cell.viewWithTag(1) as UILabel
    label.text = testArray[indexPath.row]
    return cell
}



}
EN

回答 1

Stack Overflow用户

发布于 2014-08-30 01:55:55

是否要将UICollectionView委托和数据源设置为self anywhere?我在你的代码中看不到它,这可能就是问题所在。您可能需要在viewDidLoad方法中使用它。

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

https://stackoverflow.com/questions/25573594

复制
相关文章

相似问题

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