Quote:
Originally Posted by jasonbfly
Hello!
I am stuck on something simple, and any help would be greatly appreciated!!
I was wondering if any one here knows how add sections to a tableview
I want a simple A-Z, I had a huge array with around 150 objects, but than broke into ArrayA - which holds all the objects that begin with A, ArrayB, which holds all the objects started with B and so forth to Z. I was wondering how i get it to display all my arrays in order and than display the correct heading.
Please and thank you for any help what so ever!
|
you need to implement several tableview datasource methods, check the documentation.
1) implement numberOfSections to return how many sections you want
2) implement titleForHeaderInSection to return the title for each section
3) implement the cellForRowAtIndexPath such that indexPath.row is the row within the section indexPath.section
Obviously to be able to implement these methods you need to have your data grouped first, for example a dictionary of arrays.
Because all this is quite tedious many people prefer NSFetchedResultsController these days which does all this work for your automatically, but the data needs to be in a CoreData db.
__________________
regards
Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.
Linguan – makes localizing strings file fun!
Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!