我正在使用API,需要根据图像高度调整UITableViewCell
高度。
我的if
声明必须是:
我似乎无法让这个工作,任何想法?
将根据需要发布任何额外的代码,谢谢!
- (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;
}
我在return 106 + imageHeight;
上收到一条错误,上面写着“指向接口'NSString'的指针算法,这对于这个架构和平台来说不是一个常量大小”,当应用程序到达那个点时崩溃了。 / p>
编辑:数组的内容(来自API的JSON)
"feed": [{
"headline": "xxx",
"lastModified": "xxxx",
"images": [{
"height": 300,
"alt": "xxx",
"width": 300,
"name": "xxx",
"caption": "xxx",
"url": "http://xxx.jpg"
}],
Images.h
@property (nonatomic, strong) NSNumber *height;
@property (nonatomic, strong) NSNumber *width;
@property (nonatomic, strong) NSString *caption;
@property (nonatomic, strong) NSString *url;
+ (RKObjectMapping *) mapping;
Images.m
+ (RKObjectMapping *)mapping {
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[self class] usingBlock:^(RKObjectMapping *mapping) {
[mapping mapKeyPathsToAttributes:
@"height", @"height",
@"width", @"width",
@"caption", @"caption",
@"url", @"url",
nil];
}];
return objectMapping;
}
答案 0 :(得分:1)
else {
Images *image = [feedLocal.images objectAtIndex:0];
return 106+image.size.height;
}
答案 1 :(得分:1)
您尝试使用字符串返回添加数字。而是使用:
Images *image = [feedLocal.images objectAtIndex:0];
CGFloat imageHeight = image.size.height;
return 106 + imageHeight;