我在2個視圖控制器中有2個表視圖。當我從第一個屏幕選擇一個單元格時,我想加載第二個表格,但是我的問題是:表格是空的,並且在我滾動後填充。UITableView僅在滾動後填充
這是我如何填充我的表:
當選定單元格:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSURL *url = [NSURL URLWithString:@"http://privatereisen.com/"];
ProgViewController *cd = [self.storyboard instantiateViewControllerWithIdentifier:@"progidentifview"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSString *path=[NSString stringWithFormat :@"dok/TV/pays/italie/json/chaine%d.json",indexPath.row];
[httpClient postPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
{resultofData = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil];
NSString *valuKey=[NSString stringWithFormat :@"chaine%d",indexPath.row];
NSArray *testArray =[resultofData valueForKey:valuKey];
cd.categ=[[NSArray alloc]initWithArray:testArray];
cd.categArray=[[NSArray alloc]initWithArray:self.categoryArray];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[[[UIAlertView alloc]initWithTitle:@":(" message:@"Pas d'internet !" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]show];
// NSLog(@"[HTTPClient Error]: %@", error.localizedDescription);
}];
[self.navigationController pushViewController:cd animated:YES];
[tableView cellForRowAtIndexPath:indexPath].selected = NO;
}
和ProgViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cprogCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifproecell"];
cell.heure.text = [[_categ objectAtIndex:indexPath.row]objectForKey:@"horaire_programme"];
cell.type.text = @"";
cell.desc.text = [[_categ objectAtIndex:indexPath.row]objectForKey:@"nom_programme"];
return cell;
}
+1有效點,這將是一個更好的代碼結構方法。我只是回答提出的問題。 – Tim 2015-02-24 11:54:09