2016-03-11 29 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 
     } 
} 
相關問題