我有表显示酒店,如果他们最喜欢或不。如果宿舍是最喜欢的,在旅馆的排行配件视图我放置了最喜欢的图像。但是这张图片并没有显示在目标旅舍。我随机放置在tableView中的其他单元格中。这里是代码:uitableview重复图像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 50) reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
//First get the dictionary object
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Countries"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
if (![favorites count] == 0) {
if ([favorites containsObject:[array objectAtIndex:indexPath.row]]) {
NSUInteger indexx = [favorites indexOfObject:cellValue];
if ([[favorites objectAtIndex:indexx] isEqual:cellValue]) {
// here is the image view
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage:[UIImage imageNamed:@"small_ItsMyFavorite.png"]];
imageView.frame = CGRectMake(276, 0, 50, 50);
[cell addSubview:imageView];
[imageView release];
}
}
}
}
}
return cell;
}
我在寻找和搜索,是什么问题?
工作非常好。它解决了问题! – theShay 2012-07-22 12:25:47
太棒了!'prepareForReuse'帮我 – 2013-11-29 09:28:15