Sections and Index in Sqlite's UITableView (FMDB)


I am trying to get sections and index for a UITableView from Sqlite (I use FMDB as a wrapper).
I just can't figure out where to start.
I can read the information from the database and save it in NSMutableArray .

I tried the following site, but it uses plist. http://www.icodeblog.com/2010/12/10/implementing-uitableview-sections-from-an-nsarray-of-nsdictionary-objects/

Any advice would be appreciated.

+4
source share
1 answer

you need to create an array of arrays. the main array will represent the table partitions, while the internal arrays will be the contents of the partitions.

In numberOfSectionsInTableView put

 return [mainArray count]; 

In cellForRowAtIndexPath :

 NSMutableArray *tempDict = [mainArray objectAtIndex:indexPath.section]; NSArray *tempArray = [tempDict objectAtIndex:indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@"%@", [tempArray valueForKey:@"name"]]; cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [tempArray valueForKey:@"detail"]]; return cell; 

ps The last object is an NSDictionary in my case, so I use valueForKey . Good luck

0
source

All Articles