Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 基于图像大小的单元格行高度_Ios_Objective C_Uitableview_Heightforrowatindexpath - Fatal编程技术网

Ios 基于图像大小的单元格行高度

Ios 基于图像大小的单元格行高度,ios,objective-c,uitableview,heightforrowatindexpath,Ios,Objective C,Uitableview,Heightforrowatindexpath,我正在使用API,需要根据图像高度调整UITableViewCell高度。 我的if语句需要: 如果没有图像,则将高度设置为140,否则 如果有图像,则将高度设置为106+图像高度 我好像没办法让它工作,有什么想法吗 将根据需要发布任何额外代码,谢谢 - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { Feed *feedLocal = [headl

我正在使用API,需要根据图像高度调整
UITableViewCell
高度。

我的
if
语句需要:

  • 如果没有图像,则将高度设置为140,否则
  • 如果有图像,则将高度设置为106+图像高度
我好像没办法让它工作,有什么想法吗

将根据需要发布任何额外代码,谢谢

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
if ([feedLocal.images count] == 0) {
        return 140;
    }
else {
        Images *image = [feedLocal.images objectAtIndex:0];
        NSString *imageHeight = [NSString stringWithFormat:@"%@", image.height];
        return 106 + imageHeight;
    }
我在
返回106+imageHeight时出错上面写着“在指向接口'NSString'的指针上的算术运算,对于这个架构和平台来说,它不是一个恒定的大小”,当应用程序碰到这个位置时就会崩溃

编辑:数组的内容(来自API的JSON)

图像.h

@property (nonatomic, strong) NSNumber *height;
@property (nonatomic, strong) NSNumber *width;
@property (nonatomic, strong) NSString *caption;
@property (nonatomic, strong) NSString *url;

+ (RKObjectMapping *) mapping;
图像

+ (RKObjectMapping *)mapping {
    RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[self class] usingBlock:^(RKObjectMapping *mapping) {
        [mapping mapKeyPathsToAttributes:
        @"height", @"height",
         @"width", @"width",
         @"caption", @"caption",
         @"url", @"url",
         nil];
    }];

    return objectMapping;
}

你试过这个密码吗

else {

  Images *image = [feedLocal.images objectAtIndex:0];
  return 106+image.size.height;

 }

您试图返回一个带字符串的数字的加法。而是使用:

    Images *image = [feedLocal.images objectAtIndex:0];
    CGFloat imageHeight = image.size.height;
    return 106 + imageHeight;

为什么要在数字中添加字符串?还有什么是image.height?UIImage没有height属性。@rdelmar感谢您的回复
image.height
应该是从
Feed
JSON响应获取高度。我是新来的,所以我不确定这是否回答了你的问题,我没有做正确的事情,但我不知道它是什么。我确定我需要在106中添加一个数字,那么有没有办法将
imageHeight
转换成一个数字?还是我想的不对?如果你需要,我会用更多的信息更新这个问题谢谢你的回复!实际上我已经试过了,它给了我一个错误,在类型为
Images
的对象上找不到属性
size
,在上面添加了数组和Images类谢谢你的回答,我实际上也尝试过这样做,但在第二行出现了错误“在“图像”的对象类型上找不到属性
size
。”。我不太清楚这是为什么?你的图片分类属性大小吗?feedLocal.images是否包含图像?Images是UIImage类的子类吗?feedLocal.Images是一个数组,其中有高度和宽度。这就是你要问的吗?谢谢你能举一个数组内容的例子吗?添加了数组和图像
    Images *image = [feedLocal.images objectAtIndex:0];
    CGFloat imageHeight = image.size.height;
    return 106 + imageHeight;