应用程序在我的数据填充之前进行segue,导致表视图no填充

时间:2014-05-08 17:56:29

标签: ios segue uistoryboardsegue

我有一个查询iTunes的应用程序。当数据返回时,我想从搜索屏幕切换到显示歌曲的tableview。

我的问题:我收回了数据,但是在数据恢复之前我的segue正在发生,所以numberOfRowsInSection计数仍为0,我的应用程序就停止了。我不明白为什么条件在我的performselector方法之前没有执行。

这是我的代码:

    - (IBAction)searchForTrack:(id)sender {
NSString *trackName = [[NSString alloc]init];
tracks = [[NSMutableArray alloc]init];
trackName = _searchText.text;
NSURLSession *session = [NSURLSession sharedSession];
NSString *appURL = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@",trackName];
//NSLog(appURL);
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:appURL] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSMutableDictionary *jsonDict= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    //NSLog(@"%@", jsonDict); 
    if (jsonDict)
    {
        for (id trackDict in [jsonDict objectForKey:@"results"]){
            Track *track = [[Track alloc] initWithJSONDictionary:trackDict];
            NSString *trackName = [trackDict objectForKey:@"trackName"];
            NSString *artistName = [trackDict objectForKey:@"artistName"];
            NSString *trackPrice = [trackDict objectForKey:@"trackPrice"];
            NSString *releaseDate = [trackDict objectForKey:@"releaseDate"];
            NSString *primaryGenreName = [trackDict objectForKey:@"primaryGenreName"];
            [tracks addObject:track];
    }
}
else
    {
        NSLog(@"No Darn Tracks Were Found or Something else is screwed up");
    }
}];
[dataTask resume];
[self performSelector:@selector(switchToTableview)];
}

1 个答案:

答案 0 :(得分:0)

您不会显示完整代码,但

}];

给出条件代码在块中执行的线索。

由于可能导致问题的阻塞,您的代码不会以一行一行的方式执行,但您需要发布所有代码以确认并建议最佳解决方案(这将删除块,或添加完成部分到块。)