我不知道的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