Я застрял с этим. Я объясню с моим кодом
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSNumber *cellno=[NSNumber numberWithUnsignedInteger:indexPath.row];
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 13, 15,18)];
imgView.image=[UIImage imageNamed:@"lock.png"];
tickView = [[UIImageView alloc] initWithFrame:CGRectMake(200, 13, 15,18)];
tickView.image=[UIImage imageNamed:@"tick.png"];
switch (indexPath.row) {
case 0:
cell.textLabel.text=@"apples";
if ([appDelegate.connected containsObject:cellno]) { //condition
[cell.contentView addSubview:tickView];
}else{
[cell.contentView addSubview:imgView];
}
break;
}
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
В первый раз, когда загружается табличное представление, в представление содержимого ячеек добавляется подпредставление 'imgView', а после некоторой операции выполняется условие 'if' и добавляется 'tickView'.
Проблема в том, что oldview не скрывается и не удаляется, и, следовательно, появляются оба изображения.
Помощь будет принята с благодарностью
![Both the tickview and imgView appears](https://i.stack.imgur.com/x84MX.png)