任何人都可以和我一起检查这段代码吗?我无法在我的表格视图中获取 json 项目,我只能在 Xcode 控制台上获取它们并且我找不到错误。………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………
/*
static NSString * const BaseURLStringg = @"http://api- public.guidebox.com/v1.43/Tunisia/rKgEWJbFg0kgEHrcGXPKhPDo0XtTafyC/movies /all/250/250";
@interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSMutableArray *tableData;
@property (weak, nonatomic) IBOutlet UITableView *tab;
*/
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:BaseURLStringg];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"JSON: %@", responseObject);
NSDictionary *jsonDict = (NSDictionary *) responseObject;
NSArray *products = [jsonDict objectForKey:@"results"];
[products enumerateObjectsUsingBlock:^(id obj,NSUInteger idx, BOOL *stop){
NSString *title= [NSString stringWithFormat:@"%@ ", [obj objectForKey:@"title"] ];
NSString *release_year = [NSString stringWithFormat:@"%@ ", [obj objectForKey:@"release_year"] ];
NSString *themoviedb= [NSString stringWithFormat:@"%@ ", [obj objectForKey:@"themoviedb"] ];
NSString *original_title= [NSString stringWithFormat:@"%@ ", [obj objectForKey:@"original_title"] ];
[_tab clearsContextBeforeDrawing];
[_tableData insertObject:title atIndex:0];
[_tableData insertObject:release_year atIndex:1];
[_tableData insertObject:themoviedb atIndex:2];
[_tableData insertObject:original_title atIndex:3];
}]; //[self tableData];
// [_tableData addObject:@"gggggggg"];
dispatch_sync(dispatch_get_main_queue(), ^{
//self.tableData=[[NSMutableArray alloc]initWithArray:responseObject];
[self.tab reloadData];
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"Error: %@", error);
}];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section{
return [self.tableData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* mycell=[tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
// NSInteger nameindex=[_DB.arrColumnNames indexOfObject:@"name"];
//NSString* name=[[_myarray objectAtIndex:indexPath.row] objectAtIndex:nameindex];
if (_tableData!=nil){
UILabel *title = [mycell.contentView viewWithTag:101];
UILabel *release_year = [mycell.contentView viewWithTag:102];
UILabel *themoviedb = [mycell.contentView viewWithTag:103];
UILabel *original_title = [mycell.contentView viewWithTag:104];
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];
}
//mycell.textLabel.text=@"eererr";
mycell.textLabel.textColor = [UIColor blackColor];
mycell.contentView.backgroundColor = [UIColor clearColor];
mycell.backgroundColor = [UIColor clearColor];
return mycell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end