I have a really strange Problem. With 64bit Devices i always geht a wrong cell height. On 32bit Devices it looks correct like this:
On Devices with 64bit Architecture, it looks like this:
This is my function, and YES i changed it from float to CGFloat after 64bit Devices got released....
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
GFBlockTableRowItem* row = [self.blockTable.tableRows objectAtIndex:indexPath.row];
CGFloat maxHeight = 0.0f;
for (NSUInteger i=0; i<row.tableColumns.count; ++i) {
NSString* widthValue = [self.blockTable.tableColWidths objectAtIndex:i];
CGFloat percentage = widthValue.integerValue/100.0f;
NSString* string = [row.tableColumns objectAtIndex:i];
CGSize constraint = CGSizeMake(self.frame.size.width*percentage, FLT_MAX);
CGSize size = calculateSizeWithInsets(string, self.defaultCellFont, constraint, GTDefaultTableEdgeInsets);
maxHeight = MAX(size.height, maxHeight);
}
LogDebug(@"height %li: %.3f", (long)indexPath.row, maxHeight);
return maxHeight;
}
EDIT 1:
typedef NS_ENUM(NSInteger, GTVerticalTextAlignment) {
GTVerticalTextAlignmentTop,
GTVerticalTextAlignmentCenter,
GTVerticalTextAlignmentBottom
};
/**top, left, bottom, right*/
static UIEdgeInsets GTDefaultTableEdgeInsets = {0.0f, 0.0f, 0.0f, 0.0f};
static UIEdgeInsets GTDefaultTextViewEdgeInsets = {8.0f, 4.0f, 8.0f, 4.0f};
CGSize calculateSizeWithInsets(NSString *text,UIFont *font, CGSize size, UIEdgeInsets insets) {
// GT_SIZE_CONSTRAINT_NONE
CGSize constraint = size;
UIEdgeInsets effective = UIEdgeInsetsMake((insets.top + GTDefaultTextViewEdgeInsets.top),
(GTDefaultTextViewEdgeInsets.left + insets.left),
(insets.bottom + GTDefaultTextViewEdgeInsets.bottom),
(GTDefaultTextViewEdgeInsets.right + insets.right));
if (constraint.width != GT_SIZE_CONSTRAINT_NONE) {
constraint.width = constraint.width - (effective.left + effective.right);
}
if (constraint.height != GT_SIZE_CONSTRAINT_NONE) {
constraint.height = constraint.height - (effective.top + effective.bottom);
}
CGSize textSize = calculateSize(text, font, constraint);
if (constraint.width == GT_SIZE_CONSTRAINT_NONE) {
textSize.width += effective.left + effective.right;
}
if (constraint.height == GT_SIZE_CONSTRAINT_NONE) {
textSize.height += effective.top + effective.bottom;
}
return textSize;
}
In my case below method was being used
- (float)tableView: (UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
instead of this updated method.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
In 64 bit architecture float should be replaced with CGFloat
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.