任何人都可以和我一起检查这个代码我不能在我的表视图中获取json项目,我只能在Xcode控制台上获取它们,我找不到错误。 ...................................................................................................................................................... ................................................................................................................
This doesn't work unfortunately
答案 0 :(得分:0)
您正在设置数据:
[_tableData insertObject:title atIndex:0];
[_tableData insertObject:release_year atIndex:1];
[_tableData insertObject:themoviedb atIndex:2];
[_tableData insertObject:original_title atIndex:3];
但是你正在读出如下数据:
title.text= [_tableData objectAtIndex:indexPath.row];
release_year.text= [_tableData objectAtIndex:indexPath.row];
themoviedb.text= [_tableData objectAtIndex:indexPath.row];
original_title.text= [_tableData objectAtIndex:indexPath.row];
indexPath.row将是相同的整数(例如,对于该部分中的第一个单元格,它将为0)。因此,对于该单元格,标题将设置为title.text
,release_year.text
,themoviedb.text
和original_title.text
。这不是你想要的。您应该使用NSDictionary并将其添加到self.tableData。例如,您应该用以下代码替换第一位代码:
NSDictionary *movieDictionary = @{@"title":title,@"release_year":release_year,@"themoviedb":themoviedb,@"original_title":original_title};
[self.tableData addObject:movieDictionary];
in cellForRowAtIndexPath:
NSDictionary *movieDictionary = self.tableData[indexPath.row];
title.text= movieDictionary[@"title"];
release_year.text= movieDictionary[@"release_year"];
themoviedb.text= movieDictionary[@"themoviedb"];
original_title.text= movieDictionary[@"original_title"];
答案 1 :(得分:0)
我没有阅读所有代码,但我认为这一行可能是错误的。
dispatch_sync(dispatch_get_main_queue(), ^{
//self.tableData=[[NSMutableArray alloc]initWithArray:responseObject];
[self.tab reloadData];
});
GCD这样写,会锁定主线程,然后UI刷新就不会执行,如果你想要reloadData
,你需要像下面那样写
dispatch_asyn(dispatch_get_main_queue(), ^{
//self.tableData=[[NSMutableArray alloc]initWithArray:responseObject];
[self.tab reloadData];
});
希望能帮到你。
答案 2 :(得分:0)
尝试这种类型的代码
NSURL *URL = [NSURL URLWithString:@"http://api.androidhive.info/songs/albums.php"];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
[manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
cource_data=[responseObject valueForKey:@"name"];
NSLog(@"JSON: %@", cource_data);
[self.tbl_cource reloadData];
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];