我使用: self performSelector:@selector(loadData) withObject:nil ... 看起来只在“loadData”中使用某些命令,但其余的不是。
这是我的viewdidload:
- (void)viewDidLoad
{
[super viewDidLoad];
[mActivity startAnimating];
[self performSelector:@selector(loadData) withObject:nil afterDelay:2];
//[mActivity stopAnimating];
}
这是加载数据:
-(void)loadData
{
[mActivity startAnimating];
NSLog(@"Start LoadData");
AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *selectData=[NSString stringWithFormat:@"select * from k_proverb ORDER BY RANDOM()"];
qlite3_stmt *statement;
if(sqlite3_prepare_v2(delegate.db,[selectData UTF8String], -1,&statement,nil)==SQLITE_OK){
NSMutableArray *Alldes_str = [[NSMutableArray alloc] init];
NSMutableArray *Alldes_strAnswer = [[NSMutableArray alloc] init];
while(sqlite3_step(statement)==SQLITE_ROW)
{
NSString *des_strChk= [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,3)];
if ([des_strChk isEqualToString:@"1"]){
NSString *des_str= [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,4)];
[Alldes_str addObject:des_str];
}
}
Alldes_array = Alldes_str;
Alldes_arrayAnswer = Alldes_strAnswer;
}else{
NSLog(@"ERROR '%s'",sqlite3_errmsg(delegate.db));
}
listOfItems = [[NSMutableArray alloc] init];
NSDictionary *desc = [NSDictionary dictionaryWithObject:
Alldes_array forKey:@"description"];
[listOfItems addObject:desc];
//[mActivity stopAnimating];
NSLog(@"Finish loaData");}
它只给我打印 2 行,但没有将我的数据加载到表中,但是如果我从“loadData”内部复制所有代码并过去在“viewDidLoad”中,它将数据加载到表中。
请提供任何建议或帮助。