0
我有一個字符串數組,必須在一個單元格標籤:UICollectionView只顯示最後一個單元格
var sounds = ["a", "b", "c", "d"]
這裏是cellForItemAtIndexPath的代碼:
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
var cell: MyCollectionViewCell = collectionView?.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as MyCollectionViewCell
cell.frame = CGRectMake(0, 0, 100, 100)
cell.label.text = sounds[indexPath.row]
cell.label.textColor = UIColor.blackColor()
cell.label.font = UIFont(name: "Arial", size: 12)
cell.label.textAlignment = NSTextAlignment.Center
return cell
}
的問題是,當我運行的應用程序只有一個單元格,它正在顯示數組中最後一項的文本。
我想是不是在屬性檢查工作的原因,當我點擊它說,項目是一個1
有沒有一種方法,使項目數爲array.count的的CollectionView?
這裏是項目設置我的號碼:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
return sounds.count
}
你爲什麼要設置單元的框架? – 2014-11-20 21:27:05
另外,請發佈您的其他集合視圖委託和數據源方法。我還注意到''array'沒有用在你發佈的代碼中。 – 2014-11-20 21:27:58
我設置了單元格的框架,使其更大。是的,我知道這只是一個例子陣列,我會改變它 – 2014-11-20 21:30:41