2013-05-01 8 views
0

"href" 웹 주소를 UITableViewcell.textlabel.text으로 표시해야합니다. 어떤 도움이라도 대단히 감사하겠습니다.JSON 응답에서 cell.textLabel.text 표시

JSON :

"grandfathers": [{ 
     "id": "60", 
     "sons": [{ 
      "id": "30", 
      "grandsons": [{ 
       "id": "10", 
       "links": { 
        "api": { 
         "news": { 
          "href": "http://api.website.com/v1/family/grandfathers/sons/grandsons/10/news" 
         }, 
        }, 

@interface :

@property (strong, nonatomic) NSArray *grandfathers; 
@property (strong, nonatomic) NSMutableArray *sons; 
@property (strong, nonatomic) NSArray *grandsons; 

테이블 뷰 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"standardCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    Grandfather *grandfatherLocal = [grandfathers objectAtIndex:0]; 
    Son *sonLocal = [grandfatherLocal.sons objectAtIndex:0]; 

    // Not sure what to do here to get to the "href" eventually 
    // This was my best guess... 
    Grandson *grandsonLocal = [sonLocal.grandsons objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [grandsonLocal.links.api.news.href valueForKey:@"href"]; 
}; 

내가하는 방법을 잘 모르겠어요 그 시점에서 중첩 된 데이터로 이동합니다. (참고로 나는 그래서 내가 여기에 뭘하는지에 대한 컨텍스트를 먹으 렴, 모델을 설정하고 RestKit을 사용하고 있습니다.)

편집 : 나는 테이블에 표시 아무것도 점점하지거야, 그리고 출력에 오류가 단지 "키 패스의 오브젝트 매핑을 찾을 수 없습니다 : ''"

편집 : 요청에 따라 손자 인터페이스 :

@interface Team : NSObject 
@property (nonatomic, strong) NSNumber *id; 
@property (nonatomic, strong) Links *links; 
+ (RKObjectMapping *) mapping; 
@end 

편집 : 알레산드로가 내 질문에 완벽하게 대답했습니다. 아래를보십시오. BTW, 그는 저를 도우려고 뛰어 넘었고, 나는 위대하다 -

고마워! grandsonLocal가 제대로 가져온 경우

+0

아마도 관련이 있습니다 - 'cell'은 설정에 따라 nil이 될 수 있습니다. 귀하의 셀에 대한 class/nib 파일을 등록하셨습니까? 문서에서 : _ "재사용 할 수있는 셀이없고 클래스 또는 nib 파일을 등록하지 않은 경우이 메서드는 nil을 반환합니다."_ –

+0

valueForKeyPath : @ "links.api.news.href"? – Marc

+0

@AaronBrager 셀은 nil이 아니지만 머리가 들었을 때 감사합니다. – Realinstomp

답변

1

, 그럼 나는이 작동하지 않는 경우 그냥 줄에 중단 점을 넣어 grandsonLocal의 그 속성의 내용을 검사하려고

cell.textLabel.text = grandsonLocal.links.api.news.href; 

를 사용한다고 생각합니다.

+0

'grandsonLocal'은 이전'UIViewController'에서'UITableView'에 연결된 모든'id'를 나열했기 때문에 올바르게 가져 오는 중입니다 ... 그래서 어떤 이유로'links'에서 올바르게 매핑하는 방법을 모르겠습니다 'href'까지 계속 – Realinstomp

+0

Grandson @interface를 게시 할 수 있습니까? 링크 NSDictionary 속성 또는 "Link"객체와 같은 것을 가리키는 링크 속성이 있어야합니다. –

+0

확실하게 코드를 게시했습니다. 당신은 맞습니다.'link' 객체 ('api' 객체를 가리키는'api' 객체를 가리키는'Links' 속성이 있습니다.이 객체는'news' 객체를 가리키는'news' 속성을 가지고 있습니다. 'NSString'' href' 속성이 있고'href'의 매핑을 가지고 있습니다) – Realinstomp

관련 문제