ios - How can I add tag value in sender while creating an UICollectionViewCell? -
i'm noob swift, have question solve trouble in app.
in uiview have added collection view sub view, in each cell added different image inside "wrapper view", question is...
how can add gesture receives tag value sender each cell? example, when tap cell it'll print indexpath
i have code:
func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { var cell:uicollectionviewcell = collectionview.dequeuereusablecellwithreuseidentifier("collectioncell", forindexpath: indexpath) as! uicollectionviewcell; cell.backgroundcolor = uicolor.bluecolor().colorwithalphacomponent(0); //agregamos imagen la celda var imageview = uiimageview(frame: cgrectmake(0, 0, cell.frame.width - 0, cell.frame.height - 0)) var image = uiimage(named: "car_aguas_gerber_7.png") imageview.image = image cell.backgroundview = uiview() cell.backgroundview!.addsubview(imageview) // sección donde creamos el tap para cada imageview // creamos el tap gesture recognizer let tapgesture = uitapgesturerecognizer(target: self, action: "tapgesture:") // se lo adjudicamos al image view previo cell.addgesturerecognizer(tapgesture) // nos aseguramos que tenga interacción hacia el usuario cell.userinteractionenabled = true cell.tag = indexpath.row; println(cell.tag); //una vez creada la celda la regresamos completa. return cell; }
thanks lot in advance knowledge , :)
you have when adding gesture recognizer cell. when gesture happens, parameter passed cell. when declaring tapgesture method access sender's tag property.
func tapgesture(sender: uitapgesturerecognizer) { var tag = sender.view!.tag //do want }
Comments
Post a Comment