我正在使用自定义tablecell,但我在使用下面的代码解析我的uilabel中的JSON时出现问题,这非常有用。把东西放在我的UILabel中我很简单
cell.One.text = @"xx";
/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell"
owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]])
cell = (CustomCell *)oneObject;
}
return cell;
}
但是当我试图解析我通常做的事情时
- (void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* lastgame = [json objectForKey:@"items"];
NSDictionary* game = [lastgame objectAtIndex:0];
cell.One.text = [NSString stringWithFormat:@"%@",
[strijd objectForKey:@"One"]
];
}
但是在这一行我收到了一个错误:(使用未声明的标识符'cell')现在有人如何修复thix?
cell.One.text = [NSString stringWithFormat:@"%@",
[strijd objectForKey:@"One"]
];
答案 0 :(得分:1)
cell.One.text = [NSString stringWithFormat:@"%@",
[strijd objectForKey:@"One"]
];
您的单元格未在此方法中声明,您必须在cellForRowAtIndexPath:
在您使用:CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];