Можете ли вы показать мне, как передавать разные данные на UICollection каждый раз, когда пользователь нажимает кнопку, каждая кнопка предназначена для одной передачи данных, и у меня есть три кнопки. Мне нужно знать, как передавать данные, используя кнопку в качестве триггера для изменения данных. Это мой код до сих пор:Как передавать разные данные на 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
}
Посмотрите выше, я только что редактировал мой вопрос @ jycr753 – GrumphyGuy
Не могли бы вы добавить определение 'filterArray'. Кроме того, вы подключили свои кнопки из своей раскадровки (если вы используете ее) с помощью IBOutlets? Скопируйте этот код тоже –