简体   繁体   中英

sections and index in UITableView from Sqlite (FMDB)


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

I have tried the following site but he is using a plist. http://www.icodeblog.com/2010/12/10/implementing-uitableview-sections-from-an-nsarray-of-nsdictionary-objects/

Any advice would be appreciated.

you need to make an array of arrays. the main array will represent the tableview sections while the inner arrays will be the contents of the sections.

In the numberOfSectionsInTableView put

return [mainArray count];

In the 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;

psthe last object is a NSDictionary in my case, that's why I use valueForKey . Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM