ios - Swift disable hidden property for UIImageView in Cell in UICollectionView -


i using swift 2 xcode 7 beta. rendering uicollectionview cells have image , label in it. image should hidden @ time of viewload.

this code:

func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {     let cell = collectionview.dequeuereusablecellwithreuseidentifier("contactcell", forindexpath: indexpath) as! contactcell     cell.contactname.text = contactsnames[indexpath.row]     cell.selectedicon.hidden = true      return cell }  // selection of item func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath) {     let cell = collectionview.dequeuereusablecellwithreuseidentifier("contactcell", forindexpath: indexpath) as! contactcell     cell.selectedicon.hidden = false } 

i have tried during loading put in first collectionview method cell.selectedicon.hidden = true, showed items. still interaction didn't work (when click on item, didn't show).

can advice how solve this? thanks!

first of read dequeuereusablecellwithreuseidentifier method:

call method data source object when asked provide new cell collection view. method dequeues existing cell if 1 available or creates new 1 based on class or nib file registered.

to access 1 specific cell there severals options can use in specific case think method cellforitematindexpath(_:)(this method not same use set initial values cells, put above) best choice, in following way:

func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath) {    let cell = collectionview.cellforitematindexpath(indexpath) as! contactcell    cell.selectedicon.hidden = false } 

i hope you.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -