我不知道的SQLite在后台如何运行querys在What are best practices that you use when writing Objective-C and Cocoa?如何在iPhone的后台运行sqlite?
这提示是我的尝试:
- (void) run:(NSString *)sql {
NSArray *data = [NSArray arrayWithObjects:
sql,
[self returnItemClass],
nil];
NSInvocationOperation *operation =
[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(loadRecords:)
object:data];
[self.queue addOperation:operation];
[operation release];
}
- (void) loadRecords:(NSArray *)data {
NSLog(@"Runing sql");
NSString * sql = [data objectAtIndex:0];
Class cls = [data objectAtIndex:1];
Db *db= [Db currentDb];
NSArray *list = [db loadAndFill:sql theClass:cls];
[UIAppDelegate performSelectorOnMainThread:@selector(recordsLoaded:)
withObject:list
waitUntilDone:YES];
}
- (void) recordsLoaded:(NSArray *)data {
NSLog(@"Loading sql");
for (DbObject *o in data) {
[self.objectCache setObject:o forKey:[NSNumber numberWithInt:o.Id]];
}
}
不过,我得到一个错误,当尝试运行
[UIAppDelegate performSelectorOnMainThread:@selector(recordsLoaded:)
withObject:list
waitUntilDone:YES];
抱怨关于不能发送消息给recordsLoaded。
这是正确的答案?
如何在UITableView中填充数据?
我知道后台进程。我在说这里的多线程.. – mamcx 2009-04-09 19:30:20
那么也许你不应该有*说*后台进程,呃? – 2009-04-09 23:12:28
不知道为什么你被downvoted。+1 – Randolpho 2009-04-10 00:31:46