Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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 UIImageView';UITableviewCell中的内部内容大小_Ios_Iphone_Xcode_Imageview_Tableview - Fatal编程技术网

Ios UIImageView';UITableviewCell中的内部内容大小

Ios UIImageView';UITableviewCell中的内部内容大小,ios,iphone,xcode,imageview,tableview,Ios,Iphone,Xcode,Imageview,Tableview,我有一个带有Imageview的Tableview单元格。 我想以全尺寸显示图像,即图像高度与实际图像相同 Tableview单元格高度应与实际图像高度相同 我如何才能做到这一点? 谢谢,我假定您有一个具有图像名称的数组 使用以下方法 对于目标-C - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ UIImage *image

我有一个带有Imageview的Tableview单元格。 我想以全尺寸显示图像,即图像高度与实际图像相同

Tableview单元格高度应与实际图像高度相同

我如何才能做到这一点?


谢谢,

我假定您有一个具有图像名称的数组

使用以下方法

对于目标-C

  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
            UIImage *image = [UIImage imageNamed:[self.arrImages objectAtIndex:indexPath.row]];
            if (image == nil){
               return 36; //return any static value
            } else {
               return image.size.height;
            }
    }
用于Swift

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    let image = UIImage(named: arrImages[indexPath.row])
    image?.size.height
    if image == nil {
        return 36  //return any static value
    } else {
        return (image?.size.height)!
    }

}

我假设您有一个具有图像名称的数组

使用以下方法

对于目标-C

  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
            UIImage *image = [UIImage imageNamed:[self.arrImages objectAtIndex:indexPath.row]];
            if (image == nil){
               return 36; //return any static value
            } else {
               return image.size.height;
            }
    }
用于Swift

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    let image = UIImage(named: arrImages[indexPath.row])
    image?.size.height
    if image == nil {
        return 36  //return any static value
    } else {
        return (image?.size.height)!
    }

}

我使用的代码与我使用的代码相同,对我有效。请确保您使用的是自动调整大小,而不是自动布局或大小类。使用此代码后,请告诉我问题所在?我使用的代码与我使用的代码相同,对我有效。请确保您使用的是自动调整大小,而不是自动布局或大小类。使用后请告诉我问题所在这