Wednesday 15 May 2013

xcode - How to make a table from a dictionary with multiple content types in Swift? -



xcode - How to make a table from a dictionary with multiple content types in Swift? -

i have made nsarray nsdictionary objects containing contents downloaded api. made tableview object on main.storyboard prototype cell uiimage label , 2 text labels contents. how can set info array table each cell same style prototype shows contents of nsdictionary array.

you have implement uitableviewdatasource methods remember set datasource property of tableview viewcontroller 1 object(your nsdictionary) array , set cell labels , imageview it's data.

func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int func tableview(tableview: uitableview, cellforrowatindexpath indexpath:nsindexpath) -> uitableviewcell

here total code illustration in swift. objective-c similar

class masterviewcontroller: uitableviewcontroller { var objects = [ ["name" : "item 1", "image": "image1.png"], ["name" : "item 2", "image": "image2.png"], ["name" : "item 3", "image": "image3.png"]] override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { homecoming objects.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { allow cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) uitableviewcell allow object = objects[indexpath.row] cell.textlabel?.text = object["name"]! cell.imageview?.image = uiimage(named: object["image"]!) cell.otherlabel?.text = object["otherproperty"]! } }

xcode uitableview swift ios8 xcode6

No comments:

Post a Comment