UItableview Expandble 单元格部分图像问题
Posted
技术标签:
【中文标题】UItableview Expandble 单元格部分图像问题【英文标题】:UItableview Expandble Cell Section Image issue 【发布时间】:2014-11-28 10:38:23 【问题描述】:我有关于部分图像的图像问题,当我展开单元格时,它会在随机行中显示图像...
我必须在部分中显示图像视图
图片 + 部分中的部分名称
我的问题是图像显示在 Some random Row's ...
这是我的代码哪里错了??
if (!indexPath.row)
// first row
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
client_Image = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,50,50)];
client_Image.image = [UIImage imageNamed:@"mdclogo.png"];
[cell addSubview:client_Image];
cell.textLabel.text =[NSString stringWithFormat:@" %@",tclient.clientName];
UIFont *fontBold = [UIFont fontWithName:@"Arial Rounded MT Bold" size:30];
cell.textLabel.font = fontBold;
cell.textLabel.textColor = [UIColor blackColor];
else
cell.textLabel.text = [NSString stringWithFormat:@" %@",tclient.clientName];
UIFont *fontBold = [UIFont fontWithName:@"Arial Rounded MT Bold" size:20];
cell.textLabel.font = fontBold;
cell.textLabel.textColor = [UIColor blackColor];
client_Image = [[UIImageView alloc] initWithFrame:CGRectMake(5,5,39,36)];
client_Image.image = [UIImage imageNamed:@"mdclogo.png"];
[client_Image setClipsToBounds:YES];
[cell addSubview:client_Image];
cell.layer.cornerRadius = 0.5f;
cell.layer.masksToBounds = YES;
// only top row showing
if ([expandedSections containsIndex:indexPath.section])
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeUp];
else
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeDown];
else
// all other rows (client flows)
cell.textLabel.text = ((MDCFlowDetails * )[tclient.aflows getFlow:indexPath.row - 1]).title;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
cell.indentationWidth = 2;
UIFont *fontBold = [UIFont fontWithName:@"Arial" size:25];
cell.textLabel.font = fontBold;
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
else
cell.indentationWidth = 2;
UIFont *myFont = [UIFont fontWithName:@"Arial" size: 16.0 ];
cell.textLabel.font = myFont;
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
【问题讨论】:
【参考方案1】:当您因为可重用性而滚动时,图像会添加到单元格中。试试下面的一个
for (UIView *subview in [cell.contentView subviews])
if ([subview isKindOfClass:[UIImageView class]])
[subview removeFromSuperview];
你也可以用tag
解决
【讨论】:
以上是关于UItableview Expandble 单元格部分图像问题的主要内容,如果未能解决你的问题,请参考以下文章
UITableView - 由单元格本身控制的动态单元格高度
UItableview 单元格的动态高度与 UItableview 单元格内的 UItableview
UITableView - 如何识别我是不是将一个单元格拖到一个单元格上?