0

I would like to implement a tableview with the number of sections that is known before run time but the number of rows per section are determined during run time. Something like this where there will always be 26 sections (1 for each letter) but the number of places under each letter would change.
https://camo.githubusercontent.com/dcba4426063e4d2b8a48c27ceb8831f3582f3647/687474703a2f2f73332e6d656469612e73717561726573706163652e636f6d2f70726f64756374696f6e2f313336383332312f31363130363738322f5f554c4954732d6e4456376b2f5450526739505f4e7448492f41414141414141414569382f67465761695444335967772f73313630302f4170706c6525324244656661756c7425324253656374696f6e2532425469746c6525324256696577732e706e67

Would I use static cells or dynamic prototypes and can someone give me some pointers on how to implement this?

Lightsout
  • 3,454
  • 2
  • 36
  • 65
  • 2
    Post the code you have up until now. – bsarrazin Jun 29 '15 at 23:01
  • 1
    Just use a standard tableview with dynamic prototypes where `tableView:numberOfRowsInSection:` returns a static integer. and `tableView:numberOfRowsInSection:` returns the correct number of rows for each section. – Robotic Cat Jun 29 '15 at 23:13
  • @RoboticCat thanks I will try that, will the section headers still appear if I use dynamic prototypes? – Lightsout Jun 29 '15 at 23:18
  • Use the `tableView:titleForHeaderInSection:` method and return a String specific to each section if you want to have section headers. See this answer: http://stackoverflow.com/q/10505708/558933 – Robotic Cat Jun 29 '15 at 23:38

2 Answers2

5

Just use a standard tableview with dynamic prototypes and implement the following methods where:

Community
  • 1
  • 1
Robotic Cat
  • 5,899
  • 4
  • 41
  • 58
1

You can refer this: Addressbook UI Sample

Though this is in Objective C but its easy to know what functions you need to call from swift code as both swift and Objective C tableview delegates are almost same.

sanjana
  • 3,034
  • 2
  • 25
  • 31