Ios UIImage未按预期显示
上面的代码应该是在点击时将UIImageView添加到现有UITableViewCell。这是调用该方法的行(showmageattableview:forrowatinexpath): 但这是点击tableviewcell时的结果:Ios UIImage未按预期显示,ios,objective-c,uitableview,uiimageview,uiimage,Ios,Objective C,Uitableview,Uiimageview,Uiimage,上面的代码应该是在点击时将UIImageView添加到现有UITableViewCell。这是调用该方法的行(showmageattableview:forrowatinexpath): 但这是点击tableviewcell时的结果: 我做错了什么?您没有更改UITableViewCell的高度 我认为更好的方法是在xib/情节提要设计中包含UIImageView。假设您有某种dto对象存储单元格中显示的数据,您可以在其上保留一个boolean,指示是否应显示图像 在您的上选择Rowatin
我做错了什么?您没有更改
UITableViewCell
的高度
我认为更好的方法是在xib
/情节提要设计中包含UIImageView
。假设您有某种dto
对象存储单元格中显示的数据,您可以在其上保留一个boolean
,指示是否应显示图像
- 在您的
上选择RowatineXpath
,您将更新该布尔值
,并执行[tableView reloadData]
- 在
cellforrowatinexpath
中,您将根据boolean
隐藏/显示UIImageView
- 在
高度FORROWATINDEXPATH
中,您将再次检查布尔值,以便相应地更新高度
希望能有帮助
- (void)showImageAtTableView:(UITableView *)tableView forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView indexPathsForSelectedRows].count) {
if ([[tableView indexPathsForSelectedRows] indexOfObject:indexPath] != NSNotFound) {
//cell is expanded
CGFloat frameHeight = [[self.widthArray objectAtIndex:indexPath.row] floatValue];
CGFloat frameWidth = [[self.heightArray objectAtIndex:indexPath.row] floatValue];
//CGFloat yOrigin = [self configureHeightForRowAtIndexPath:indexPath];
CGRect imageFrame = CGRectMake(0,
12,
frameWidth,
frameHeight);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageFrame];
imageView.image = [UIImage imageNamed:@"testImage.jpg"];
imageView.contentMode = UIViewContentModeCenter;
//configue which cell
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
[cell.contentView addSubview:imageView];
}
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
[self updateTableView];
//get and show the image at selected cell
[self showImageAtTableView:tableView forRowAtIndexPath:indexPath];
}