我有這個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