Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIImage未按预期显示_Ios_Objective C_Uitableview_Uiimageview_Uiimage - Fatal编程技术网

Ios UIImage未按预期显示

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

上面的代码应该是在点击时将UIImageView添加到现有UITableViewCell。这是调用该方法的行(showmageattableview:forrowatinexpath):

但这是点击tableviewcell时的结果:


我做错了什么?

您没有更改
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];
}