你能告诉我每次用户按下按钮时如何在UICollection上传递不同的数据,每个按钮用于一个数据,我有三个按钮。我需要知道如何通过使用按钮作为触发器来更改数据来传递数据。到目前为止,这是我的代码:
@IBAction func openNewFilter(sender: AnyObject) {
self.collectionView.dataSource = self
}
func numberOfSections() -> Int {
return 2
}
//For the collectionView, number of filters in the section
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return self.filters.count
} else if section == 1 {
println("great")
return 1
} else {
return 0
}
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("FILTER_CELL", forIndexPath: indexPath) as FilterThumbnailCell
var filterThumbnail = self.filterThumbnails[indexPath.row]
cell.filterTitle.text = filterThumbnail.filterName
//Lazy Loading
if indexPath.section == 0 {
// set up the standard cell, using the data from the army
if filterThumbnail.filteredThumbnail != nil {
cell.imageView.image = filterThumbnail.filteredThumbnail
} else {
cell.imageView.image = filterThumbnail.originalThumbnail
//filterThumbnail is a class instance
filterThumbnail.generateThumbnail({ (image) -> Void in
if let cell = collectionView.cellForItemAtIndexPath(indexPath) as? FilterThumbnailCell {
cell.imageView.image = image
}
})
}
} else if indexPath.section == 1 {
//set up the "+" cell
println("booya")
}
return cell
}
答案 0 :(得分:0)
您可以在每个操作中初始化具有不同内容的filterArray
,并在CollectionView
中使用它。
答案 1 :(得分:0)
您已经将数组加载到Collection视图中,即self.filters。您需要做的是按下每个按钮,使用新值重新启动阵列,然后调用
[<Your collectionView> reloadData];
顺便提一下,我可以在上面的代码中看到使用Collection View部分吗?