使用64位设备的TableView高度错误

时间:2014-05-19 11:07:48

标签: ios objective-c uitableview 32bit-64bit

我有一个非常奇怪的问题。对于64位设备,我总是使用错误的单元高度。在32位设备上看起来像这样:

enter image description here

在具有64位架构的设备上,它看起来像这样:

enter image description here

这是我的功能,在64位设备发布后,我将它从float更改为CGFloat ....

-(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;
}

编辑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;
}

1 个答案:

答案 0 :(得分:0)

在我的情况下,正在使用以下方法

- (float)tableView: (UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath

而不是这个更新的方法。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

在64位架构中,float应替换为CGFloat