hide button in a collectionview cell when trigger - ios

i have collectionview that contain del button and add
cell.coupon_add.tag = indexPath.row
cell.coupon_add?.layer.setValue(id, forKey: "coupon_id")
cell.coupon_add?.layer.setValue(uID, forKey: "user_id")
cell.coupon_add?.addTarget(self, action: #selector(ViewController.addItem(_:)), forControlEvents: UIControlEvents.TouchUpInside)
func addItem(sender:UIButton) {
let point : CGPoint = sender.convertPoint(CGPointZero, toView:collectionview)
let indexPath = collectionview!.indexPathForItemAtPoint(point)
let cell = collectionview.dequeueReusableCellWithReuseIdentifier("listcell", forIndexPath: indexPath!) as! ListCell
let coupon_id : String = (sender.layer.valueForKey("coupon_id")) as! String
let user_id : String = (sender.layer.valueForKey("user_id")) as! String
if user_id == "empty" {
self.login()
}else{
print("adding item**",indexPath)
cell.coupon_add.hidden = true
cell.coupon_del.hidden = true
let buttonRow = sender.tag
print(buttonRow)
}
}
i want to hide the add button when trigger. i just get the value of the indexPath but i dont know how to hide it without refresh the collectionview

Create a custom cell
class CustomCell: UICollectionViewCell {
#IBOutlet weak var label: UILabel!
#IBOutlet weak var delButton: UIButton!
#IBOutlet weak var addButton: UIButton!
#IBAction func addTapped(sender: AnyObject) {
delButton.removeFromSuperview()
addButton.removeFromSuperview()
}
}
Typical CollectionView Controller
class ViewController: UICollectionViewController {
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10;
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CustomCell
cell.label.text = "Cell \(indexPath.row)"
return cell
}
}
And your button will gone, when you hit them

Related

How to get values from different cells?

I have a table view that includes multiple prototype cells. I want to get values of textField in these cells and append an array, when tapped a button.
Cells has an object that called element. I want to append this element to elementsArray in my view controller. The problem is when cellForRow method worked this elements keys is created but because of cellForRowAt method works only one time, "value" key of element object take initial value of txtContent.
How can I take txtContent text after write a text for each cell?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let object = surveyDetailArray.first!.elements[indexPath.row]
switch object.type {
case CellConfig.email.rawValue:
let cell = tableView.dequeueReusableCell(withIdentifier: "EmailCell", for: indexPath) as! EmailCell
cell.lblTitle.text = object.title
cell.txtContent.inputAccessoryView = toolBar
cell.element["formElementId"] = object.id as AnyObject
cell.element["options"] = optionArray as AnyObject
elementsArray.append(cell.element as AnyObject)
return cell
case CellConfig.number.rawValue:
let cell = tableView.dequeueReusableCell(withIdentifier: "NumberCell", for: indexPath) as! NumberCell
cell.lblTitle.text = object.title
cell.txtContent.inputAccessoryView = toolBar
cell.txtContent.keyboardType = .numberPad
cell.element["formElementId"] = object.id as AnyObject
cell.element["options"] = optionArray as AnyObject
elementsArray.append(cell.element as AnyObject)
return cell
}
My cell class
class EmailCell: UITableViewCell,UITextFieldDelegate {
#IBOutlet weak var lblTitle: UILabel!
#IBOutlet weak var txtContent: CustomTextField!
var element = ["formElementId":"",
"value":"",
"options":[]] as [String : Any]
override func awakeFromNib() {
super.awakeFromNib()
txtContent.backgroundColor = #colorLiteral(red: 0.1570051014, green: 0.1588717997, blue: 0.2081049681, alpha: 0.1)
txtContent.layer.borderWidth = 0
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
txtContent.delegate = self
// Configure the view for the selected state
}
func textFieldDidEndEditing(_ textField: UITextField) {
element["value"] = textField.text!
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let object = surveyDetailArray.first!.elements[indexPath.row]
switch object.type {
case CellConfig.email.rawValue:
let cell = tableView.dequeueReusableCell(withIdentifier: "EmailCell", for: indexPath) as! EmailCell
cell.txtContent.delegate = self
return cell
case CellConfig.number.rawValue:
let cell = tableView.dequeueReusableCell(withIdentifier: "NumberCell", for: indexPath) as! NumberCell
return cell
}
extension ViewController: UITextFieldDelegate{
func textFieldDidEndEditing(_ textField: UITextField) {
var cell: UITableView Cell!
if let emailCell: UITableViewCell = textField.superview.superview as? EmailCell{
cell = emailCell
}
if let numbCell: UITableViewCell = textField.superview.superview as? NumberCell{
cell = numbCell
}
var table: UITableView = cell.superview as UITableView
let textFieldIndexPath = table.indexPathForCell(cell)
// HERE DO THE UPDATION YOU WANT TO DO
}
}

iOS how know which button is pressed CollectionView with custom delegate

So I have a cells in a collectionview with 3 buttons in it. To trigger code with these buttons I have implemented a custom delegate. Now the code is being triggered, but I don't know from which cell the code triggered. How can I best implement this? Here is some of my code.
Protocol:
protocol OverViewDelegate {
func registerButtonClicked()
func evaluateButtonClicked()
func overviewButtonClicked()
}
cellForItemAt:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sessionCell", for: indexPath) as? SessionCollectionViewCell
let session: SessionModel
session = DebugData.shared.sessionArray[indexPath.row]
cell?.sessionImage.image = #imageLiteral(resourceName: "carControl")
cell?.sessionNameLabel.text = session.name
cell?.sessionLocationLabel.text = session.location
cell?.overViewDelegate = self
return cell!
}
cell:
import UIKit
import IBAnimatable
#IBOutlet weak var sessionImage: UIImageView!
#IBOutlet weak var sessionNameLabel: UILabel!
#IBOutlet weak var sessionLocationLabel: UILabel!
#IBOutlet weak var sessionRegisterButton: AnimatableButton!
#IBOutlet weak var sessionOverviewButton: AnimatableButton!
#IBOutlet weak var sessionEvaluateButton: AnimatableButton!
var overViewDelegate: OverViewDelegate?
#IBAction func registerButtonClicked(_ sender: Any) {
overViewDelegate?.registerButtonClicked()
}
#IBAction func overviewButtonClicked(_ sender: Any) {
overViewDelegate?.overviewButtonClicked()
}
#IBAction func evaluateButtonClicked(_ sender: Any) {
overViewDelegate?.evaluateButtonClicked()
}
Any help would be appriciated.
Pass indexPath value in Cell class return back indexPath on Button Click function
protocol:-
protocol OverViewDelegate {
func registerButtonClicked(_ indexPath : IndexPath)
func evaluateButtonClicked(_ indexPath : IndexPath)
func overviewButtonClicked(_ indexPath : IndexPath)
}
cellForItemAt:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sessionCell", for: indexPath) as? SessionCollectionViewCell
let session: SessionModel
session = DebugData.shared.sessionArray[indexPath.row]
cell?.sessionImage.image = #imageLiteral(resourceName: "carControl")
cell?.sessionNameLabel.text = session.name
cell?.sessionLocationLabel.text = session.location
cell?.overViewDelegate = self
cell?.indexPath = indexPath
return cell!
}
cell:
#IBOutlet weak var sessionImage: UIImageView!
#IBOutlet weak var sessionNameLabel: UILabel!
#IBOutlet weak var sessionLocationLabel: UILabel!
#IBOutlet weak var sessionRegisterButton: AnimatableButton!
#IBOutlet weak var sessionOverviewButton: AnimatableButton!
#IBOutlet weak var sessionEvaluateButton: AnimatableButton!
var overViewDelegate: OverViewDelegate?
var indexPath : IndexPath?
#IBAction func registerButtonClicked(_ sender: Any) {
overViewDelegate?.registerButtonClicked(indexPath)
}
#IBAction func overviewButtonClicked(_ sender: Any) {
overViewDelegate?.overviewButtonClicked(indexPath)
}
#IBAction func evaluateButtonClicked(_ sender: Any) {
overViewDelegate?.evaluateButtonClicked(indexPath)
}
get cell using :-
let cell = tableView.cellForRow(at: indexPath)
The best way to do is in protocol method send back the cell..
for example
protocol OverViewDelegate {
func registerButtonClicked(cell: SessionCollectionViewCell)
func evaluateButtonClicked(cell: SessionCollectionViewCell)
func overviewButtonClicked(cell : SessionCollectionViewCell)
}
and on button click
#IBAction func overviewButtonClicked(_ sender: Any) {
overViewDelegate?.overviewButtonClicked(cell: self)
}
and on you viewcontroller when delegate method implemented
func overviewButtonClicked(cell: SessionCollectionViewCell) {
// here you get the cell and all the properties you want to access of that cell and also
if let indexPath = self.tableView.indexPath(for: cell) {
// do what you want to do
}
}
Put a variable in your cell and save your session data model instance in cellForRowAt. Then update your delegate methods and add for each method a session parameter.
So you have the instance of your data model for each button press
You can check with button tag in cellForItemAt:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sessionCell", for: indexPath) as? SessionCollectionViewCell
cell.YOUR_BUTTON.tag = indexPath.item
return cell!
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sessionCell", for: indexPath) as? SessionCollectionViewCell
let session: SessionModel
session = DebugData.shared.sessionArray[indexPath.row]
cell.sessionRegisterButton.tag = indexPath.row // --- add this
..........
cell?.sessionImage.image = #imageLiteral(resourceName: "carControl")
cell?.sessionNameLabel.text = session.name
cell?.sessionLocationLabel.text = session.location
cell?.overViewDelegate = self
return cell!
}
#IBAction func registerButtonClicked(_ sender: Any) {
let cellIndex = sender.tag // this will be the cell index
overViewDelegate?.registerButtonClicked()
}
In cellForItemAt: method you can specify tag value and when a button is tapped you can check sender.tag to check which button is tapped.
You can achieve it by giving tags to all button in cellForItemAt: as bellow
cell.sessionRegisterButton.tag = indexPath.item
cell.sessionOverviewButton.tag = indexPath.item
cell.sessionEvaluateButton.tag = indexPath.item
And get index back by :
#IBAction func registerButtonClicked(_ sender: Any) {
let senderButton : UIButton = sender as! UIButton
let index : Int = senderButton.tag
overViewDelegate?.registerButtonClicked()
}
#IBAction func overviewButtonClicked(_ sender: Any) {
let senderButton : UIButton = sender as! UIButton
let index : Int = senderButton.tag
overViewDelegate?.overviewButtonClicked()
}
#IBAction func evaluateButtonClicked(_ sender: Any) {
let senderButton : UIButton = sender as! UIButton
let index : Int = senderButton.tag
overViewDelegate?.evaluateButtonClicked()
}

Problems updating UITableView cell and SwiftyPickerPopover

The problem is that when I am selecting some value (in the field picker -SwiftyPickerPopover-) in a row, the action updates the same value (selected in picker) for all rows.
The code that I am using for this for the ViewController (with UITableView inside):
func btnExpenseTypePressed(at index: IndexPath) {
var tiposGasto: [String] = [String]()
for gasto in dataManager.expensesType {
tiposGasto.append(gasto.tipoGasto!)
}
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: index) as! ExpenseDetailCell
StringPickerPopover.appearFrom(
originView: cell.btnExpenseType,
baseViewController: self,
title: "Tipos de Gasto",
choices: tiposGasto,
initialRow:0,
doneAction: { selectedRow, selectedString in
print("Seleccion \(selectedString)")
//self.valueSelected = selectedString
cell.btnExpenseType.setTitle(selectedString, for: .normal)
self.tableView.reloadData()
} ,cancelAction: { print("cancel")}
)
}
func btnCostCenterPressed(at index: IndexPath) {
var centroCoste: [String] = [String]()
for centro in dataManager.costsCenter {
centroCoste.append(centro.centroCoste!)
}
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: index) as! ExpenseDetailCell
StringPickerPopover.appearFrom(
originView: cell.btnCostCenter,
baseViewController: self,
title: "Centro de Coste",
choices: centroCoste,
initialRow:0,
doneAction: { selectedRow, selectedString in
print("Seleccion \(selectedString)")
//self.valueSelected = selectedString
cell.btnCostCenter.setTitle(selectedString, for: .normal)
self.tableView.reloadData()
} ,cancelAction: { print("cancel")}
)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : UITableViewCell? = UITableViewCell()
if tableView == self.tableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) as! ExpenseDetailCell
cell.selectionStyle = .none
cell.delegate = self
debugPrint("First table load \(firstTableLoad)")
if firstTableLoad {
cell.btnCostCenter.setTitle(dataManager.costsCenter[0].centroCoste, for: .normal)
cell.btnExpenseType.setTitle(dataManager.expensesType[0].tipoGasto, for: .normal)
firstTableLoad = false
}
return cell
}
if tableView == self.tableViewImages {
let cell = tableView.dequeueReusableCell(withIdentifier: "imagesCellIdentifier", for: indexPath) as! ExpenseImageCell
cell.imageView?.image = UIImage(named: "imgPlaceholder")
cell.selectionStyle = .none
return cell
}
return cell!
}
The btnExpenseTypePressed and btnCostCenterPressed methods are delegate from the ExpenseDetailCell:
protocol ExpenseDetailDelegate {
func switchChanged(at index: IndexPath)
func amountEditedChanged(at index: IndexPath)
func btnExpenseTypePressed(at index: IndexPath)
func btnCostCenterPressed(at index: IndexPath)
}
class ExpenseDetailCell: UITableViewCell {
var delegate: ExpenseDetailDelegate!
var indexPath: IndexPath!
var dataManager = DataManager.sharedInstance
#IBOutlet weak var txtAmountNumber: UITextField!
#IBOutlet weak var txtId: UITextField!
#IBOutlet weak var txtAmountPercent: UITextField!
#IBOutlet weak var lblTotal: UILabel!
#IBOutlet weak var lblSeparator: UILabel!
#IBOutlet weak var lblPercent: UILabel!
#IBOutlet weak var btnExpenseType: UIButton!
#IBOutlet weak var btnCostCenter: UIButton!
#IBOutlet weak var switchID: UISwitch!
#IBAction func btnExpenseTypePressed(_ sender: Any) {
debugPrint("En btnExpenseTypePressed")
self.delegate?.btnExpenseTypePressed(at: indexPath)
debugPrint("El INDEX \(indexPath)")
}
#IBAction func btnCostCenterPressed(_ sender: Any) {
debugPrint("En btnCostCenterPressed")
self.delegate?.btnCostCenterPressed(at: indexPath)
debugPrint("El INDEX \(indexPath)")
}
#IBAction func amountEditedChanged(_ sender: Any) {
debugPrint("En amountEditedChanged")
self.delegate?.amountEditedChanged(at: indexPath)
lblTotal.text = txtAmountNumber.text
}
#IBAction func switchChanged(_ sender: Any) {
debugPrint("En value changed")
self.delegate?.switchChanged(at: indexPath)
if switchID.isOn {
debugPrint("Dentro if")
txtId.text = ""
txtId.isEnabled = false
} else {
txtId.isEnabled = true
}
}
}
I am using SWIFT 3.
I believe the error comes from a missunderstanding of what you want to do and what you are acctually doing.
You want: Change one value in one cell
You do: Change one value in all cells ON cell creation.
When you call: self.tableView.reloadData() in unc btnExpenseTypePressed(at index: IndexPath) iOS calls
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) again and again skipping the `firstTableLoad = false` and loading all the tableviewCells with the same value.
You have also set the index to 0 in DataManager.costsCenter[0] which will mean that all the cells on creation will have the same value.
My suggestion: Do your changes in:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
}
If by any chance this doesn't help you check clean the cell in :
override func prepareForReuse()
{
super.prepareForReuse()
}
or just set it like this:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : UITableViewCell? = UITableViewCell()
if tableView == self.tableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) as! ExpenseDetailCell
cell.selectionStyle = .none
cell.delegate = self
cell.setMyCustomText("")...
}
return cell
}

Stepper on tableview cell (swift)

I put stepper both outlets and action into tableview cell and using protocol delegate to connect it to tableview. When i tapped stepper in first row, stepper value appear normaly in first row but its also appear in some random row. how to fix this?
TableViewCell
protocol ReviewCellDelegate{
func stepperButton(sender: ReviewTableViewCell)
}
class ReviewTableViewCell: UITableViewCell {
#IBOutlet weak var countStepper: UIStepper!
#IBOutlet weak var stepperLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
#IBAction func stepperButtonTapped(sender: UIStepper) {
if delegate != nil {
delegate?.stepperButton(self)
stepperLabel.text = "x \(Int(countStepper.value))"
}
}
ViewController
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "reviewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ReviewTableViewCell
var imageView: UIImageView?
let photoG = self.photos[indexPath.row]
imageView = cell.contentView.viewWithTag(1) as? UIImageView
//let layout = cell.goodiesImage
let tag = indexPath.row // +1
cell.tag = tag
photoG.fetchImageWithSize(CGSize(width: 1000, height: 1000), completeBlock: { image, info in
if cell.tag == tag {
imageView?.image = image
cell.goodiesImage.image = image
}
})
func stepperButton(sender: ReviewTableViewCell) {
if let indexPath = tableView.indexPathForCell(sender){
print(indexPath)
}
}
Reset the value of stepper while loading your cell. you can reset the cell property values in cell's prepareForReuse method. add the following method in your ReviewTableViewCell class.
override func prepareForReuse()
{
super.prepareForReuse()
countStepper.value = 0.0
}
In tableViewCell VC:
1 - add these field
var cellDelegate: cellProtocol?
var index: IndexPath?
2 - then add this in the delegate:
func onStepperClick(index: Int, sender: UIStepper)
3 - when you have dragged your stepper over as an action use this:
#IBAction func cellStepper(_ sender: UIStepper) {
cellDelegate?.onStepperClick(index: (index?.row)!, sender: sender)
sender.maximumValue = 1 //for incrementing
sender.minimumValue = -1 //for decrementing
//this will make sense later
}
In ViewController
1 - add these to the tableView function that has the cellAtRow variable.
cell.cellDelegate = self
cell.index = indexPath
2 - Use this instead of your stepperButton function
func onStepperClick(index: Int, sender: UIStepper) {
print(index)
if sender.value == 1.0{
//positive side of stepper was pressed
}else if sender.value == -1.0{
//negative side of stepper was pressed
}
sender.value = 0 //resetting to zero so sender.value produce different values on plus and minus
}
Hope this works for you
As mentioned by #A-Live, your component is being reused and so need to be updated.
So in your view controller:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "reviewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ReviewTableViewCell
var imageView: UIImageView?
let photoG = self.photos[indexPath.row]
imageView = cell.contentView.viewWithTag(1) as? UIImageView
//let layout = cell.goodiesImage
let tag = indexPath.row // +1
cell.tag = tag
photoG.fetchImageWithSize(CGSize(width: 1000, height: 1000), completeBlock: { image, info in
if cell.tag == tag {
imageView?.image = image
cell.goodiesImage.image = image
}
})
cell.countStepper.value = XXX[indexPath.row].value; //Here you update your view
cell.stepperLabel.text = "x \(Int(cell.countStepper.value))" //And here
And
func stepperButton(sender: ReviewTableViewCell) {
if let indexPath = tableView.indexPathForCell(sender){
print(indexPath)
XXX[sender.tag].value = sender.counterStepper.value //Here you save your updated value
}
NOTE:
1.MY Cell class is just normal..All changes are in viewcontroller class
2.I have taken stepper and over it added ibAddButton with same constraint as ibStepper
class cell: UITableViewCell {
#IBOutlet weak var ibAddButton: UIButton!
#IBOutlet weak var ibStepper: UIStepper!
#IBOutlet weak var ibCount: UILabel!
#IBOutlet weak var ibLbl: UILabel!
}
1.define empty int array [Int]()
var countArray = [Int]()
2.append countArray with all zeros with the number of data u want to populate in tableview
for arr in self.responseArray{
self.countArray.append(0)
}
3.in cell for row at
func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! cell
let dict = responseArray[indexPath.row] as? NSDictionary ?? NSDictionary()
cell.ibLbl.text = dict["name"] as? String ?? String()
if countArray[indexPath.row] == 0{
cell.ibAddButton.tag = indexPath.row
cell.ibStepper.isHidden = true
cell.ibAddButton.isHidden = false
cell.ibCount.isHidden = true
cell.ibAddButton.addTarget(self, action: #selector(addPressed(sender:)), for: .touchUpInside)
}else{
cell.ibAddButton.isHidden = true
cell.ibStepper.isHidden = false
cell.ibStepper.tag = indexPath.row
cell.ibCount.isHidden = false
cell.ibCount.text = "\(countArray[indexPath.row])"
cell.ibStepper.addTarget(self, action: #selector(stepperValueChanged(sender:)), for: .valueChanged)}
return cell
}
4.objc functions
#objc func stepperValueChanged(sender : UIStepper){
if sender.stepValue != 0{
countArray[sender.tag] = Int(sender.value)
}
ibTableView.reloadData()
}
#objc func addPressed(sender : UIButton){
countArray[sender.tag] = 1//countArray[sender.tag] + 1
ibTableView.reloadData()
}

Why are my images not changing in UICollectionView with the indexPath?

I have a Collection View with the ImageCollectionViewClass that I have defined as well as a class for the image. However the images in the collection view aren't changing with the indexPath and I can't work out why
class metricImage {
var featuredImage: UIImage!
init(featuredImage: UIImage!){
self.featuredImage = featuredImage
}
static func createImage() -> [metricImage] {
return [metricImage(featuredImage: UIImage(named: "prodOne.png")!), metricImage(featuredImage: UIImage(named: "prodTwo.png")!), metricImage(featuredImage: UIImage(named: "prodThree.png")!),metricImage(featuredImage: UIImage(named: "prodFour.png")!),metricImage(featuredImage: UIImage(named: "prodFive.png")!),metricImage(featuredImage: UIImage(named: "prodSix.png")!)]
}
}
class ImageCollectionViewCell: UICollectionViewCell
{
var images: metricImage! {
didSet{
updateUI()
}
}
#IBOutlet weak var featuredImageView: UIImageView!
private func updateUI() {
featuredImageView?.image! = images.featuredImage
}
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if collectionView == prodCollectionView {
//print("collectionViewOne")
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("productCell", forIndexPath: indexPath) as! ImageCollectionViewCell
print(indexPath.item)
cell.images = self.prodImage[indexPath.item]
return cell
}
I have added some statements to make sure it enters where it needs to. I am new to swift so it may be trivial. Thank you in advance

Resources