В uitableview у меня есть по крайней мере одна строка, затем я добавляю переменное число других строк, чья ячейка является пользовательской ячейкой, созданной программно с помощью uiimageview.Uiimageview установлен с локальным изображением.Это изображение восстановлено правильно, но я вижу всегда одно и то же изображение, повторяемое во всех строках.
Я пытался использовать [myImageView setNeedsDisplay];
после setImage в
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Любой намек?
РЕДАКТИРОВАТЬ
Некоторый код
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"CellWithTextIdentifier";
UITableViewCell *cell;
static NSString *cellIdentifier2 = @"CellWithImageIdentifier";
UITableViewCell *cell2;
UIImageView *logImageView;
switch (indexPath.row) {
case 0:
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MyCostumCell" owner:self options:nil];
cell = myCustomCell;
self.myCustomCell = nil;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
break;
default:
cell2 = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
if (cell2 == nil) {
cell2 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease];
logImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(100.0, 20.0, 100.0, 100.0)] autorelease];
cell2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[cell2.contentView addSubview:logImageView];
}
cell2.selectionStyle = UITableViewCellSelectionStyleNone;
NSMutableArray *images = [[NSMutableArray alloc] init];
// here I fill the array images. It's properly filled with
// objects which have a path property with the relative path of the image
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *absolutePath = [documentsDirectory stringByAppendingPathComponent:[[images objectAtIndex:indexPath.row-1] path]];
UIImage *image = [UIImage imageWithContentsOfFile:absolutePath];
[logImageView setImage:image];
//[logImageView setNeedsDisplay];
[images release];
return cell2;
break;
}
}
РЕДАКТИРОВАТЬ 2: РАЗРЕШЕНО
Проблема заключается в logImageView.Если cell2 используется повторно, представление uiimageview не инициализируется.Решение:
cell2 = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
if (cell2 == nil) {
cell2 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease];
logImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(100.0, 20.0, 100.0, 100.0)] autorelease];
logImageView.tag = 12;
cell2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[cell2.contentView addSubview:logImageView];
}
} else {
logImageView = (UIImageView *)[cell2.contentView viewWithTag:12];
}