我正在创建一个字典应用程序,我正在尝试将这些术语加载到 iphone 字典中以供使用。这些术语是从此表(SQLite)中定义的:
id -> INTEGER autoincrement PK
termtext -> TEXT
langid -> INT
normalized -> TEXT
使用规范化是因为我用希腊语写作,并且我在 sqlite 引擎上没有用于搜索变音符号的 icu,所以我正在制作一个 termtext 变音符号/不区分大小写。它也是主要的搜索字段,与可能是“视图”字段的 termtext 形成对比。
我已经定义了一个这样的类(如 POJO):
条款.h
#import <Foundation/Foundation.h>
@interface Terms : NSObject {
NSUInteger termId; // id
NSString* termText; // termtext
NSUInteger langId; // langid
NSString* normalized; // normalized
}
@property (nonatomic, copy, readwrite) NSString* termText;
@property (nonatomic, copy, readwrite) NSString* normalized;
@property (assign, readwrite) NSUInteger termId;
@property (assign, readwrite) NSUInteger langId;
@end
条款.c
#import "Terms.h"
@implementation Term
@synthesize termId;
@synthesize termText;
@synthesize langId;
@synthesize normalized;
@end
现在在我的代码中,我使用FMDB作为SQLite数据库的包装器。我使用以下代码加载条款:
[... fmdb defined database as object, opened ]
NSMutableArray *termResults = [[[NSMutableArray alloc] init] autorelease];
FMResultSet *s = [database executeSQL:@"SELECT id, termtext, langid, normalized FROM terms ORDER BY normalized ASC"];
while ([s next]) {
Term* term = [[Terms alloc] init];
term.termId = [s intForColumn:@"id"];
[... other definitions]
[termResults addObject:term];
[term release];
}
然后将整个 termResults 加载到UITableView(在 viewdidload 上),但每次启动我的应用程序时加载最多需要 5 秒。有什么方法可以加快这个过程吗?我在SQLite上索引了 id、termText 和规范化。
*** 更新:添加了 cellForRowAtIndexPath ***
[.. standard cell definition...]
// Configure the cell
Term* termObj = [self.termResults objectAtIndex:indexPath.row];
cell.textLabel.text = termObj.termText;
return cell;