2016-03-11 30 views
0

我使用的是swift 2.0和xcode 7.我想要在应用程序中使用图像阵列的垂直集合视图。但是,当我运行我的项目UICollectionView区域显示为黑色。我已经在我的ViewController上设置了脚本,但我不知道我错过了什么。我已经设置了一个标识符和所有其他的东西。请有人帮助我。谢谢。UICollectionView在运行应用程序时显示为黑色

ViewController Script

ViewController error message

+0

你能告诉你'CollectionViewCell.swift'文件? – Thomas

+0

看起来控制台有错误(用'UICollectionViewFlowLayoutBreakForInvalidSizes'),试试看看,或者复制它到你的问题,也许这可以帮助解决神秘的问题 – pbodsk

+0

我想你可能会错过代表故事板或xib中的collectionView的数据源。 – sourav

回答

0

我做了UICollectionView显示图像,尽管我仍然需要更新大小这个例子。我遵循@pdobsk的建议来查看错误消息,它说我应该考虑单元格大小以及边距和其他东西,因为单元格大小与集合视图的大小相同。

error fixed!

0

我想你忘记了代表,这是典型的错误。 另外,尝试使用的代码

class ExampleCollectionView: UIViewController, UICollectionViewDelegate 
{ 
    @IBOutlet weak var collectionView: UICollectionView! 
    let tshirtsArray = ["tshirt_1.png", 
    "tshirt_2.png", 
    "tshirt_3.png", 
    "tshirt_4.png"] 

    override func viewDidLoad() 
    { 
     super.viewDidLoad() 
     collectionView.delegate = self 

    } 

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

    func collectionView(cv: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell 
     { 
      let cell: UICollectionViewCell = cv.dequeueReusableCellWithReuseIdentifier("CollectionCell", forIndexPath: indexPath) 
      let collectionImageView: UIImageView = cell.viewWithTag(100) as! UIImageView 
      collectionImageView.image = UIImage(named: self. tshirtsArray[indexPath.row]) 
      return cell 
     } 
} 
相关问题