【发布时间】:2015-05-22 23:38:15
【问题描述】:
我有一个集合视图,但没有出现在屏幕上的单元格我无法访问,1...5 好的,以及索引部分第 6、7 行的单元格,它们必须滚动才能看到
func Action0(sender: UIButton!) {
for i in 0...7 {
if i != 0{
var indexPath = NSIndexPath(forRow: i, inSection: 0)
var cell = collectionView!.cellForItemAtIndexPath(indexPath)
cell!.backgroundColor = UIColor.whiteColor()
}else{
var indexPath = NSIndexPath(forRow: 0, inSection: 0)
var cell = collectionView!.cellForItemAtIndexPath(indexPath)
cell!.backgroundColor = UIColor.blueColor()
}
}
}
如何访问那些还不可见的单元格?
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! CollectionViewCell
cell.backgroundColor = UIColor.blackColor()
cell.textLabel.text = "\(indexPath.section):\(indexPath.row)"
cell.buttonView.setBackgroundImage(UIImage(named: "Good"), forState: UIControlState.Normal)
cell.buttonView.addTarget(self, action: Selector("Action\(indexPath.row):"), forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
【问题讨论】:
标签: ios swift collectionview