我需要在"href"
中将cell.textlabel.text
网址显示为UITableView
。任何帮助将不胜感激。
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,这就是我在这里所做的背景。)
修改 我没有在表格中显示任何内容,输出中的错误只是:“无法找到keyPath的对象映射:''”
修改 每个请求的孙子界面:
@interface Team : NSObject
@property (nonatomic, strong) NSNumber *id;
@property (nonatomic, strong) Links *links;
+ (RKObjectMapping *) mapping;
@end
修改 亚历山德罗完美地回答了我的问题,见下文。顺便说一句,他超越了我的帮助,我非常高兴 -
谢谢!
答案 0 :(得分:1)
如果正确获取grandsonLocal
,那么我认为您应该使用
cell.textLabel.text = grandsonLocal.links.api.news.href;
如果这不起作用,请尝试在该行中放置断点并检查grandsonLocal
及其属性的内容。