Can you show me how to passing different data on UICollection every time user push the button, each button is for one data and I have three button. I need to know how to passing data by using button as trigger to change the data. This is my code so far:
@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
}
您可以在每个操作中使用不同的内容初始化filterArray
,然后在CollectionView
使用它。
You already have your array to load data into Collection view ie self.filters. What you need to do is on press of each button re-initiate your array with new values and then call
[<Your collectionView> reloadData];
By the way is there any use of Collection View section's as i can see in above code?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.