ios - how to implement UITableViewController with multiple prototype cell programmatically in swift -


i have started learning swift , created settings page show in attached image using storyboard. reference link used http://shrikar.com/xcode-6-tutorial-grouped-uitableview/

enter image description here

same thing want programmatically i.e. want implement cellforrowatindexpath function has different prototype cell shown in below image. if possible please give example reference given example ui.

thanks

a great start project created apple. includes variety of things , demo app itself. give general info need start working uitableview , uitableviewcell.

1.create view (xib) files each of custom cells wish see in tableview. although can layout design in code, advise start out visual approach , see how goes, since must able operate freely such things auto layout, constraints, size classes, etc.

2.create uiviewcontroller single table view in it.

3.create cocoa touch class file (.swift) each of cells (xibs) created in step 1. in these files should reference stuff incluled in cell (uilabels, uiimageviews, etc.). don`t forget cells should have these same classes (open xib files, third icon on right panel)

4.create cocoa touch class file (.swift) uiviewcontroller created in storyboard. reference (mouse drag) tableview in cocoa touch class. make sure uiviewcontroller in storyboard has class set (custom class field, same cells in step 3)

5.refister nib cell in viewdidload method

         tableview.registernib(uinib(nibname: "topcell", bundle: nil), forcellreuseidentifier: "topcell")          tableview.registernib(uinib(nibname: "contentcell", bundle: nil), forcellreuseidentifier: "contentcell")          tableview.rowheight = uitableviewautomaticdimension; //<--calculates rows height          tableview.estimatedrowheight = 44.0;                 //   automatically (ios 8+) 

6.on uiviewcontroller tableview, click last button on right panel , drag "data source" along "data delegate" same view controller (yellow circular symbol).

7.make sure cocoa touch class (created in step 4) conforms protocols uitableviewdatasource, uitableviewdelegate (by implementing necessary methods)

class feedvc: uiviewcontroller, uitableviewdatasource, uitableviewdelegate { } // <-- class uiviewcontroller tableview   func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { } func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { } 

if not completly sure how implement these required methods, can them in project referenced in beginning of post.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -