Iphone 在后台sqlite数据库的表中插入数据
我需要在后台插入表中的数据。我正在使用Iphone 在后台sqlite数据库的表中插入数据,iphone,Iphone,我需要在后台插入表中的数据。我正在使用NSTimer在sqlite数据库的表中插入数据。但是在插入过程中它冻结了应用程序。我也使用了NSThread,但它也会产生同样的问题。我正在共享我正在使用的代码: [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(InsertDataInTable) userInfo:nil repeats:NO]; -(void)InsertDataInTempTabl
NSTimer
在sqlite数据库的表中插入数据。但是在插入过程中它冻结了应用程序。我也使用了NSThread
,但它也会产生同样的问题。我正在共享我正在使用的代码:
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(InsertDataInTable) userInfo:nil repeats:NO];
-(void)InsertDataInTempTable
{
DatabaseManager *objDb=[[DatabaseManager alloc]init];
[objDb setDelegate:self];
for(int i=0;i<[arrayTempTableData count];i++)
{
[objDb savedata:[dictCurrentUrlInfo objectForKey:TempTableName] elements:[arrayTempTableData objectAtIndex:i]];
}
}
#pragma mark -
#pragma mark Save Operation
-(void)savedata:(NSString *)into elements:(NSMutableDictionary *)dictInsert{
NSString *sql_String = @"";
if([into isEqualToString:TABLEFirstAidTemp])
{
sql_String = [NSString stringWithFormat:@"INSERT INTO %@ VALUES('%@', '%@', '%@')", into,[dictInsert objectForKey:@"ArticleNumber"],[dictInsert objectForKey:@"ArticleTitle"],[dictInsert objectForKey:@"ArticleCategory"]];
}
sqlite3_exec(sql_Database1, [sql_String UTF8String], nil, nil, nil);
}
[NSTimer scheduledTimerWithTimeInterval:0.0目标:自选择器:@selector(InsertDataInTable)用户信息:无重复:否];
-(void)InsertDataInTempTable
{
DatabaseManager*objDb=[[DatabaseManager alloc]init];
[objDb setDelegate:self];
对于(inti=0;i而言,解决方案是使用NSThread。可能是您实现了错误
您的代码将如下所示
-(void)InsertDataInTempTable
{
[NSThread detachNewThreadSelector:@selector(InsertingData) toTarget:self withObject:nil];
}
-(void)InsertingData
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
DatabaseManager *objDb=[[DatabaseManager alloc]init];
[objDb setDelegate:self];
for(int i=0;i<[arrayTempTableData count];i++)
{
[objDb savedata:[dictCurrentUrlInfo objectForKey:TempTableName] elements:[arrayTempTableData objectAtIndex:i]];
}
[pool release];
}
#pragma mark -
#pragma mark Save Operation
-(void)savedata:(NSString *)into elements:(NSMutableDictionary *)dictInsert{
NSString *sql_String = @"";
if([into isEqualToString:TABLEFirstAidTemp])
{
sql_String = [NSString stringWithFormat:@"INSERT INTO %@ VALUES('%@', '%@', '%@')", into,[dictInsert objectForKey:@"ArticleNumber"],[dictInsert objectForKey:@"ArticleTitle"],[dictInsert objectForKey:@"ArticleCategory"]];
}
sqlite3_exec(sql_Database1, [sql_String UTF8String], nil, nil, nil);
}
-(void)InsertDataInTempTable
{
[NSThread detachNewThreadSelector:@selector(InsertingData)to target:self with object:nil];
}
-(void)插入数据
{
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
DatabaseManager*objDb=[[DatabaseManager alloc]init];
[objDb setDelegate:self];
对于(int i=0;i