您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> ios >> 正文

ios后台处理数据存储线程

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 在类中,进行编辑下面的代码:

NSLog(@"main thread begin...");

[self performSelectorInBackground:@selector(doSomething:) withObject:nil];

NSLog(@"main thread end.....");


- (void) doSomething:(id)sender

{

NSLog( @"one thread begin..." );

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

for (int i=0; i<self.StarName_Final.count; i++) {

[self SaveToDataBase:[StarName_Final objectAtIndex:i]];

}

NSLog( @"one thread end..." );

[pool release];

}