Я пытаюсь изменить изображение внутри своего стола. Я использую [myTableView reloadData];
в другом методе (который запускается), чтобы обновить мой TableView
, и я вижу, что другие элементы в представлении таблицы освежают, но изображение остается неизменным. Что мне не хватает?Не удается обновить изображение внутри UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *lblName;
UIImageView *checkMark = [[UIImageView alloc] initWithFrame:CGRectMake(230, 0, 30, 50)];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 1, 260, 70)];
backgroundView.backgroundColor = UIColorFromRGB(0x000000, 0.3);
backgroundView.userInteractionEnabled = YES;
checkMark.image = [UIImage imageNamed:@"V.png"];
checkMark.contentMode = UIViewContentModeCenter;
checkMark.backgroundColor = [UIColor clearColor];
[backgroundView addSubview:checkMark];
[checkMark release];
[cell.contentView addSubview:backgroundView];
[backgroundView release];
}
if (something)
{
checkMark.image = [UIImage imageNamed:@"halfleft.png"];
NSLog(@"something was done");
}
return cell;
}
последний «}» перед «, если (что-то) 'должно быть перемещено прямо под' cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier] autorelease]; ' – Groot
Почему? Я не хочу продолжать добавлять subview, если ячейка не равна нулю. – Segev
Но вам нужно новое изображение, чтобы появиться на той же самой ячейке? поэтому вы просто создаете только ячейку, если она равна нулю. Каждая другая вещь должна быть вне (cell == nil) блока. – Piyuesh