我使用 sqlite 和 fmdb 包装器为 iphone 创建了一个数据库。
数据库中大约有 3500 行。它有 14 列:1 列用于 id,1 列用于名称/主要搜索词,9 列用于替代搜索词,3 列用于简短描述。
我的应用程序的第一个视图只是一个显示搜索栏的介绍性屏幕,有点像 google。实现搜索栏后,它将带您进入另一个视图,其中包含一个包含所需结果的表格。视图之间的初始转换有 1 或 2 秒的延迟。此外,表格不允许无缝滚动。最后,当您选择一个表格单元格时,它会将您无缝地带到最终视图,但是当您尝试返回表格视图时,还有 1 或 2 秒的延迟。
我用一个较小的数据库运行这个应用程序,该数据库有 3500 行但只有 5 列。在这种情况下,从数据库中删除了 9 个备选搜索词。当我在 iphone 上运行这样的应用程序时,它是相当有效的......有一个小的延迟,但它真的不明显......我可能不会因为滞后而受到影响,(我只会有假设小的延迟是正常的),如果我使用的更大的数据库不是那么明显的话。
我得出的结论是 sqlite 数据库需要一些调整,因此,我有两个主要问题。
- 我已经读过更改 sqlite db 的编译指示设置(例如:同步、日志模式、缓存大小)将提高效率。当我通过 mozilla 插件更改这些设置时,它们似乎没有保存...我将打开和关闭插件,设置将恢复为旧的默认值。我看到你可以通过 xcode 设置这些...我想知道 FMDB 包装器在哪里设置这些设置?
- 我听说索引可以大大提高速度。我真的不知道要索引什么,如果我索引某些东西,我是否必须更改 FMDB 包装器的编码?此外,在理想情况下我应该索引什么我想使用我的数据库中的所有数据(尽管我将使用与其他列不同的某些列)?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Data *data = [[[DataController instance]filterDataWithName:searchString:searchString:searchString:searchString:searchString:searchString:searchString:searchString:searchString:searchString]objectAtIndex:indexPath.row];
cell.textLabel.text = data.aDataName;
cell.detailTextLabel.text = data.aDataStatus;
// Configure the cell.
return cell;
}
-(NSMutableArray*)filterDataWithName:(NSString*)aDataName:(NSString*)altSearchTermA:(NSString*)altSearchTermB:(NSString*)altSearchTermC:(NSString*)altSearchTermD:(NSString*)altSearchTermE:(NSString*)altSearchTermF:(NSString*)altSearchTermG:(NSString*)altSearchTermH:(NSString*)altSearchTermI;
{
if ((aDataName && [aDataName length] > 0) && (altSearchTermA && [altSearchTermA length] > 0) && (altSearchTermB && [altSearchTermB length] > 0) && (altSearchTermC && [altSearchTermC length] > 0) && (altSearchTermD && [altSearchTermD length] > 0) && (altSearchTermE && [altSearchTermE length] > 0) && (altSearchTermF && [altSearchTermF length] > 0) && (altSearchTermG && [altSearchTermG length] > 0) && (altSearchTermH && [altSearchTermH length] > 0) && (altSearchTermI && [altSearchTermI length] > 0))
{
NSMutableArray *filterDataArray = [[NSMutableArray alloc]initWithArray:dataList];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(aDataName CONTAINS[cd] %@) OR (altSearchTermA CONTAINS[cd] %@) OR (altSearchTermB CONTAINS[cd] %@) OR (altSearchTermC CONTAINS[cd] %@) OR (altSearchTermD CONTAINS[cd] %@) OR (altSearchTermE CONTAINS[cd] %@) OR (altSearchTermF CONTAINS[cd] %@) OR (altSearchTermG CONTAINS[cd] %@) OR (altSearchTermH CONTAINS[cd] %@) OR (altSearchTermI CONTAINS[cd] %@)", aDataName, altSearchTermA,altSearchTermB,altSearchTermC,altSearchTermD,altSearchTermE,altSearchTermF,altSearchTermG,altSearchTermH,altSearchTermI];
[filterDataArray filterUsingPredicate:predicate];
return filterDataArray;
}
else
{
return dataList;
}
}