"href"
웹 주소를 UITableView
에 cell.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
가 제대로 가져온 경우
아마도 관련이 있습니다 - 'cell'은 설정에 따라 nil이 될 수 있습니다. 귀하의 셀에 대한 class/nib 파일을 등록하셨습니까? 문서에서 : _ "재사용 할 수있는 셀이없고 클래스 또는 nib 파일을 등록하지 않은 경우이 메서드는 nil을 반환합니다."_ –
valueForKeyPath : @ "links.api.news.href"? – Marc
@AaronBrager 셀은 nil이 아니지만 머리가 들었을 때 감사합니다. – Realinstomp