gpt4 book ai didi

ios - 64 位设备的 TableView 高度错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:22 24 4
gpt4 key购买 nike

我有一个非常奇怪的问题。对于 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;
}

最佳答案

在我的案例中,使用了以下方法

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

而不是这个更新的方法。

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

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

关于ios - 64 位设备的 TableView 高度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23736192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com