[英]Cancel [self performSelector:… withObject:nil afterDelay:20];
[英]self performSelector:@selector(loadData) withObject:nil - not working
我使用:self performSelector:@selector(loadData)withObject:nil ...看起來只在“ loadData”中使用某些命令,而其余部分則沒有。
這是我的viewdidload:
- (void)viewDidLoad
{
[super viewDidLoad];
[mActivity startAnimating];
[self performSelector:@selector(loadData) withObject:nil afterDelay:2];
//[mActivity stopAnimating];
}
這是loadData:
-(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”中,它將數據加載到表中。
有任何建議或幫助。
一些注意事項:如果根本看不到任何NSLog輸出,則performSelector成功。 您應該更改問題的標題。
如果您嘗試將數據加載到表中,則該方法應以告訴UITableView reloadData結尾(或使用開始/結束更新進行更精細的加載)結束。
如果listOfItems是支持該表的數據,則首先通過對以下內容進行硬編碼來使其工作:
-(void)loadData {
listOfItems = [NSArray arrayWithObjects:@"test1", @"test2", nil];
[self.tableView reloadData];
return;
// keep all of the code you wrote here. it won't run until you remove the return
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *string = [listOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = string;
return cell;
// keep all of the code you probably wrote for this method here.
// as above, get this simple thing running first, then move forward
}
祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.