辞書アプリを作成していて、用語をiphone辞書に読み込んで使用しようとしています。用語はこのテーブル(SQLite)から定義されています:
id -> INTEGER autoincrement PK
termtext -> TEXT
langid -> INT
normalized -> TEXT
ギリシャ語で書いていて、発音区別符号を検索するためのsqliteエンジンにicuがないため、正規化が使用されます。そのため、発音区別符号/大文字と小文字を区別しないようにしています。「ビュー」フィールドである可能性のある用語テキストとは対照的に、これはメインの検索フィールドでもあります。
私はこのようなクラス(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
今私のコードでは、 SQLiteデータベースのラッパーとしてFMDBを使用しています。次のコードを使用して用語をロードします。
[... 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秒かかります。そのプロセスをスピードアップする方法はありますか?id、termTextにインデックスを付け、SQLiteで正規化しました。
***更新:cellForRowAtIndexPathを追加しました****
[.. standard cell definition...]
// Configure the cell
Term* termObj = [self.termResults objectAtIndex:indexPath.row];
cell.textLabel.text = termObj.termText;
return cell;