我有这个UITableView,我已经从webservice解析数据并加载到NSDictionary中,它的所有工作都很好,数据显示id和imageurl到tableview中问题是logo-id,它是一个int完美展现,当我向下滚动tableview中,但是当我向上滚动的tableview它消失了,当我csroll下再次出现,并在那里停留在UITableView中显示解析的JSON
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Where we configure the cell in each row
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// }
// Configure the cell... setting the text of our cell's label
NSDictionary *dic = [json objectAtIndex:[indexPath row]];
NSString *strImage = [dic objectForKey:@"image-name-small"];
NSURL *ImageURL = [NSURL URLWithString:[strImage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
AsyncImageView *asyncImgView = [[AsyncImageView alloc] initWithFrame:CGRectMake(3, 10, 100, 100)];
asyncImgView.contentMode = UIViewContentModeScaleAspectFit;
asyncImgView.backgroundColor = [UIColor clearColor];
[asyncImgView loadImageFromURL:ImageURL];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(200, 200, 100, 25)];
lbl.text = [dic objectForKey:@"logo-id"];
[cell addSubview:lbl];
[cell addSubview:asyncImgView];
cell.textLabel.text = @"";
return cell;
}
问题可以这样使用addSubview的。使用'cell.textLabel.text = [dic objectForKey:@“logo-id”]检查;' – 2013-04-08 08:28:12
只是重用单元格而仅删除注释行if(cell == nil){创建并分配单元格} – krishh 2013-04-08 08:32:20
@MidhunMP你是对的它是addsubview问题,请解释原因..sugan.s如果我不评论这些行它显示重复的值 – 2013-04-08 08:47:34