초보자이며 StackOverflow에서 내 문제에 대한 모든 것을 읽었습니다. json 데이터가있는 응용 프로그램은 TableViewController에 아무 것도 표시하지 않습니다. 아마 뭔가 명백한 것이 빠졌을 것이지만, 도움은 대단히 감사하겠습니다. (중요한 경우 최신 Xcode 5 DP를 사용하고 있습니다.)TableViewController json 데이터가 표시되지 않습니다.
@interface TableVC : UITableViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSDictionary *kinos;
@property (retain, nonatomic) UITableView *tableView;
-(void)fetchKinos;
@end
TableVC.h
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
당신은 당신의 kinos이 JSON 데이터를 보유하고 있음을 확신? 내가 문제는 TableView와 json이 아니라는 것입니다. – geekchic
S. 먼저 응답 데이터를 확인하십시오. – Ganapathy
네, 마스터 디테일 애플리케이션으로 작업했음을 확신합니다. – onemi