ios - Working with Multiple Segues | How to use Cell data to perform specific Segues -


i displaying data in collection view, know how pass data on prepareforsegue function trying have app determine segue use depending on cell property data. (each segue goes different view controller display relevant information.)

for e.g.

if cell.type equal "1" perform segueone if of type "2" perform seguetwo.

i trying this;

 func collectionview(collectionview: uicollectionview, shouldselectitematindexpath indexpath: nsindexpath) -> bool {      let cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as! collectionviewcell      if cell[indexpath].type = "1" {         performseguewithidentifier("showpage1", sender: self)     } else if self.cell[indexpath].type = "2" {         performseguewithidentifier("showpage2", sender: self)     } else { println("error when selecting cell segue") }  } 

however error;

'collectionviewcell' not have member named subscript

has got ideas ?

assuming items in collection view can re-arranged (or might time in future), indexpath not sufficient give information cell selected. thus, imo idea give cell property feasible one.

the easiest "quick , dirty" way hardcode segue identifier string cell. not best design because introducing dependencies between app elements should know of each other.

class mycell : uicollectionviewcell {     var segue = "defaultsegue" } 

now calling appropriate segue easy in didselectitematindexpath...

self.performseguewithidentifier(cell.segue, sender:cell) 

it of course preferable use enum. safer, more readable , better maintainable.

enum segue : string {    case toinfo  = "seguetoinfo"    case tologin = "seguetologin"    // etc. } 

the ivar mycell var : segue = somedefaultvalue , can call same way.


btw: regarding original question please note following: has been pointed out, cannot subscript cell. (uicollectionviewcell not dictionary, cell["key"] not make sense.) also, not fan of dequeueing cell in more 1 place - instead call cellforitematindexpath or work in method in first place, have suggested.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -