【问题标题】:sections and index in UITableView from Sqlite (FMDB)来自 Sqlite (FMDB) 的 UITableView 中的部分和索引
【发布时间】:2011-08-15 08:58:29
【问题描述】:


我正在尝试从 Sqlite 获取 UITableView 的部分和索引(我使用 FMDB 作为包装器)。
我似乎不知道从哪里开始。
我可以从数据库中读回信息并将其存储在NSMutableArray 中。

我尝试了以下站点,但他使用的是 plist。 http://www.icodeblog.com/2010/12/10/implementing-uitableview-sections-from-an-nsarray-of-nsdictionary-objects/

任何建议将不胜感激。

【问题讨论】:

  • 您能否给我们一个您想要展示的数据模型的小预览?

标签: iphone uitableview fmdb


【解决方案1】:

你需要创建一个数组数组。主数组将表示 tableview 部分,而内部数组将是部分的内容。

numberOfSectionsInTableView

return [mainArray count];

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;

p.s.就我而言,最后一个对象是 NSDictionary,这就是我使用 valueForKey 的原因。祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多