2013-08-14 4 views
-4

초보자이며 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 
+1

당신은 당신의 kinos이 JSON 데이터를 보유하고 있음을 확신? 내가 문제는 TableView와 json이 아니라는 것입니다. – geekchic

+0

S. 먼저 응답 데이터를 확인하십시오. – Ganapathy

+0

네, 마스터 디테일 애플리케이션으로 작업했음을 확신합니다. – onemi

답변

0

당신 JSON 응답 사전 그 카운트해야하는 테이블 뷰 방식에서 반환 될 entities의 배열을 포함한다. 또한

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [[self.kinos objectForKey:@"entities"] count]; 
} 

enter image description here

, 제안, 당신은 strong 속성을 선언 할 때, _propertyName처럼 바르 액세스하는 대신 self.propertyName로 액세스하려고합니다.

희망 하시겠습니까?

-1

내 브라우저에서 내 URL (http://www.adworldmagazine.com/json.json)에 액세스했습니다.
응답은 root : dictionary가있는 JSON을 반환합니다.

그래서,

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return _kinos.count; 
} 

실 거예요 작동합니다.

사용이 대신 :

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return [_kinos objectForKey:@"entities"].count; 
    } 
+1

이것은 답변이 아닙니다. 의견입니다. – Abizern

+0

나는 문제를 해결할 수있는 방법을 포함하여 나의 대답을 편집했다. –

+0

위의 @amar가 제공 한 답변을 다시 한 번 말하십시오. – Abizern

관련 문제