How can I use multiple withReuseIdentifier
?
and here is the code because i have 4 button doesn't work when i use Identifier "1" the other buttons dosen't wrok
and here is the code
extension ViewController : UICollectionViewDataSource
{
func numberOfSections(in collectionView: UICollectionView) -> Int
{
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return interests3.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "1", for: indexPath as IndexPath) as! interestCollectionViewCell
cell.interest2 = self.interests3[indexPath.item]
return cell
}
new code
import UIKit
class interestCollectionViewCell: UICollectionViewCell
{
var interest2: Interest1! {
didSet {
updateUI()
}
}
@IBOutlet weak var futerdimageview: UIImageView!
@IBOutlet weak var interstTitleLabel: UILabel!
private func updateUI()
{
interstTitleLabel.text! = interest2.title
futerdimageview.image = interest2.featuredImage!
}
override func layoutSubviews() {
super.layoutSubviews()
self.layer.cornerRadius = 10.0
self.clipsToBounds = true
}
}
and this code
import UIKit
class Interest1
{
var title = ""
var description = ""
var featuredImage: UIImage!
var button1: UIButton!
var button2: UIButton!
var button3: UIButton!
var button4: UIButton!
init(title: String, featuredImage: UIImage!)
{
self.title = title
self.featuredImage = featuredImage
}
static func createInterest() -> [Interest1]
{
return [
Interest1(title: "One", featuredImage: UIImage(named:"001.png")!),
Interest1(title: "Two", featuredImage: UIImage(named:"002.png")!),
Interest1(title: "Three", featuredImage: UIImage(named:"003.png")!),
Interest1(title: "Four", featuredImage: UIImage(named:"004.png")!),
]
}
}