1 iphone objective-c uitableview
我创建了imageview以在cellForRowAtIndexPath方法上显示图像.我在Cell中添加了imageview作为子视图.但是当我在那时重新加载我的tableview时,单元格中的图像不会重新加载.以下是我的代码.
- (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];
}
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[arrcathatname objectAtIndex:indexPath.row]]];
[imgView setFrame:CGRectMake(20, 7, 35, 35)];
[cell addSubview:imgView];
cell.textLabel.text = [arrCatName objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
return cell;
}
Run Code Online (Sandbox Code Playgroud)
所以,我想删除我的imageview以正确重新加载图像.
我怎样才能做到这一点?
尝试将子视图添加到单元格:
[cell.contentView addSubview:imgView];
Run Code Online (Sandbox Code Playgroud)
您可以使用以下代码删除该子视图:
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3987 次 |
| 最近记录: |