使用未声明的标识符'cell'

时间:2012-04-29 11:12:14

标签: objective-c ios json cocoa-touch

我正在使用自定义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"]
                             ];

1 个答案:

答案 0 :(得分:1)

cell.One.text = [NSString stringWithFormat:@"%@",
                         [strijd objectForKey:@"One"]
                         ];

您的单元格未在此方法中声明,您必须在cellForRowAtIndexPath:

中执行此操作

在您使用:CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];

声明您的单元格后