ios - NSIndexPath does not have a member named row in swift -
i have code:
class viewcontroller: uitableviewcontroller { var myarr = [(id:1, name:"1123", description:"d1", image:"palm-tree.png"), (id:2, name:"23", description:"d2", image:"palm-tree.png"), (id:3, name:"3", description:"d3", image:"palm-tree.png"), (id:4, name:"4", description:"d4", image:"palm-tree.png")] override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if segue.identifier == "showdetail" { var indexpath = tableview.indexpathforselectedrow() allow destinationviewcontroller:detailviewcontroller = segue.destinationviewcontroller detailviewcontroller destinationviewcontroller.myarr = myarr[indexpath.row] } } }
and have error nsindexpath not have fellow member named row. how prepare that?
thanks!
update:
class viewcontroller: uitableviewcontroller { struct item { allow id: int allow name: string allow description: string allow image: string } var myarr = [item(id:1, name:"1123", description:"d1", image:"palm-tree.png"), item(id:2, name:"23", description:"d2", image:"palm-tree.png"), item(id:3, name:"3", description:"d3", image:"palm-tree.png"), item(id:4, name:"4", description:"d4", image:"palm-tree.png")] override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if segue.identifier == "showdetail" { if allow indexpath = tableview.indexpathforselectedrow() { allow destinationviewcontroller = segue.destinationviewcontroller detailviewcontroller destinationviewcontroller.myarr = [myarr[indexpath.row]] } } } }
and detailviewcontroller:
class detailviewcontroller: uiviewcontroller { struct item { allow id: int allow name: string allow description: string allow image: string } var myarr = [item(id:1, name:"1123", description:"d1", image:"palm-tree.png")] }
tableview.indexpathforselectedrow()
returns optional nsindexpath
-- need disclose access row
property:
override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if segue.identifier == "showdetail" { if allow indexpath = tableview.indexpathforselectedrow() { allow destinationviewcontroller = segue.destinationviewcontroller detailviewcontroller destinationviewcontroller.myarr = [myarr[indexpath.row]] } } }
ios swift
No comments:
Post a Comment