我是初学者,我已经阅读了 StackOverflow 上关于我的问题的所有内容 - 我的带有 json 数据的应用程序在 TableViewController 上没有显示任何内容。我可能遗漏了一些明显的东西,但是非常感谢您的帮助。(我正在使用最新的 Xcode 5 DP,如果它很重要的话)。
TableVC.h
@interface TableVC : UITableViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSDictionary *kinos;
@property (retain, nonatomic) UITableView *tableView;
-(void)fetchKinos;
@end
TableVC.m
文件是
@interface TableVC ()
@end
@implementation TableVC
- (void)viewDidLoad
{
[self fetchKinos];
[self.tableView reloadData];
[super viewDidLoad];
}
-(void)fetchKinos {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.adworldmagazine.com/json.json"]];
NSError *error;
_kinos = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
});
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _kinos.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"KinoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//[self configureCell:cell atIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSArray *entities = [_kinos objectForKey:@"entities"];
NSDictionary *kino = [entities objectAtIndex:indexPath.row];
NSDictionary *title = [kino objectForKey:@"title"];
NSString *original = [title objectForKey:@"original"];
NSString *ru = [title objectForKey:@"ru"];
cell.textLabel.text = original;
cell.detailTextLabel.text = ru;
return cell;
}
@end