简体   繁体   English

UITableView 中的部分和索引来自 Sqlite (FMDB)

[英]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).我正在尝试从 Sqlite 获取UITableView的部分和索引(我使用 FMDB 作为包装器)。
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 .我可以从数据库中读取信息并将其存储在NSMutableArray中。

I have tried the following site but he is using a plist.我尝试了以下站点,但他使用的是 plist。 http://www.icodeblog.com/2010/12/10/implementing-uitableview-sections-from-an-nsarray-of-nsdictionary-objects/ 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.您需要制作一个 arrays 数组。 the main array will represent the tableview sections while the inner arrays will be the contents of the sections.主数组将表示 tableview 部分,而内部 arrays 将是部分的内容。

In the numberOfSectionsInTableView putnumberOfSectionsInTableView

return [mainArray count];

In the cellForRowAtIndexPath :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 . psthe 最后的 object 在我的情况下是一个 NSDictionary,这就是我使用valueForKey的原因。 Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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