Reputation: 532
I'm using an API and need to adjust the UITableViewCell
height based on the Image Height.
My if
statement needs to be:
I can't seem to get this working, any ideas?
Will post any extra code as needed, thanks!
- (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;
}
I'm getting an error on return 106 + imageHeight;
that says "Arithmetic on pointer to interface 'NSString' which is not a constant size for this architecture and platform", and the app crashes when it hits that spot.
EDIT: Content of array (JSON from API)
"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;
}
Upvotes: 1
Views: 1010
Reputation: 2902
You're attempt to return the addition of a number with a string. Instead use:
Images *image = [feedLocal.images objectAtIndex:0];
CGFloat imageHeight = image.size.height;
return 106 + imageHeight;
Upvotes: 1
Reputation: 6079
have you tried this code?
else {
Images *image = [feedLocal.images objectAtIndex:0];
return 106+image.size.height;
}
Upvotes: 1