gpt4 book ai didi

ios - UITableViewCell 高度在每次旋转变化时增加 2 个像素

转载 作者:行者123 更新时间:2023-11-29 13:48:17 25 4
gpt4 key购买 nike

我有一个 UIViewController 和一个 UITableView socket ,我正在填充单元格(设置为 ivar socket ),这些单元格在与 TableView Controller 相同的 nib 文件中定义。当我使用旋转功能时,每次我旋转到新的方向时,第一个单元格都会增长 2 个像素。

这是控制台的输出。我在类的每个方法中都调用了一个 METHOD_LOG 调用,这样我就可以查看代码是否运行到了意想不到的地方,但它似乎并没有...

2011-06-08 10:10:42.050 MyApp[10927:207] METHOD_LOG: viewDidLoad /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.054 MyApp[10927:207] METHOD_LOG: viewWillAppear: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.054 MyApp[10927:207] METHOD_LOG: shouldAutorotateToInterfaceOrientation: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.056 MyApp[10927:207] METHOD_LOG: numberOfSectionsInTableView: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.056 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.056 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.057 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.057 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.058 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.058 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.059 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.059 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.060 MyApp[10927:207] item name cell height: 44.000000
2011-06-08 10:10:42.060 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.060 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.061 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.061 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.062 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.062 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.062 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.063 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.063 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.064 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.064 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.065 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.065 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.065 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.066 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.066 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.067 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.067 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.068 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.068 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.068 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.069 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.069 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.070 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.070 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.071 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.071 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.071 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.072 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.072 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.073 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.073 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.074 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.074 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.074 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.075 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.075 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.076 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.076 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.077 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.077 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.077 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.078 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.078 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.079 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.079 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.080 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.080 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.080 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.081 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.081 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.082 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.082 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.082 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.083 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.083 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.084 MyApp[10927:207] METHOD_LOG: tableView:cellForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.085 MyApp[10927:207] METHOD_LOG: tableView:cellForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.086 MyApp[10927:207] METHOD_LOG: tableView:cellForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.087 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.088 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:42.088 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.619 MyApp[10927:207] METHOD_LOG: shouldAutorotateToInterfaceOrientation: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.622 MyApp[10927:207] METHOD_LOG: numberOfSectionsInTableView: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.623 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.623 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.624 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.624 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.625 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.625 MyApp[10927:207] METHOD_LOG: tableView:titleForHeaderInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.625 MyApp[10927:207] METHOD_LOG: tableView:numberOfRowsInSection: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.626 MyApp[10927:207] METHOD_LOG: tableView:heightForRowAtIndexPath: /Users/me/path/to/the/source/code/ItemDetailViewController.m
2011-06-08 10:10:49.626 MyApp[10927:207] item name cell height: 46.000000

如您所见,加载 View 后,唯一被调用的方法是 shouldAutorotateToInterfaceOrientation 和 TableView 委托(delegate)方法。第一次看到单元格高度时,它是 Interface Builder 中定义的默认值,但第二次,它不知何故大了两个像素。这些方法中没有任何代码会修改任何对象的边界或框架。

任何人对可能发生的事情或如何诊断问题有任何想法?我想过设置一个 KVO,但我认为我无法用它来获取单元格的框架。

编辑:这是返回特定索引路径处行的高度的代码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
METHOD_LOG;

int idx = [indexPath section];

if (idx == SECTION_ITEM)
{
NSLog(@"item name cell height: %f", itemNameCell.frame.size.height);
return itemNameCell.frame.size.height;
}
else if (idx == SECTION_DESCRIPTION)
{
return itemDescriptionCell.frame.size.height;
}
...
... other section identifiers here, you get the idea
...

return 44.0;
}

编辑 2:这是创建和返回单元格的代码:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
METHOD_LOG;

UITableViewCell *cell;

int idx = [indexPath section];

if (idx == SECTION_ITEM)
{
cell = itemNameCell;
UILabel *label = (UILabel *)[cell viewWithTag:1];
label.text = [[jobItem jItemRef] blankIfNULL];
}
else if (idx == SECTION_DESCRIPTION)
{
cell = itemDescriptionCell;
UITextView *textView = (UITextView *)[cell viewWithTag:1];
textView.text = [[jobItem jItemDesc] blankIfNULL];
}
...
... again, you get the idea
...

return cell;
}

最佳答案

尝试在第一次需要时将 itemNameCell 的高度保存到您的方法中的静态 CGFloat,然后从那时起就使用它。我猜这只是 UI 中的一些自动调整大小,随着您的旋转而叠加。

这假定您不会想要以编程方式更改单元格的高度(因为您是在 IB 中设置它)。

关于ios - UITableViewCell 高度在每次旋转变化时增加 2 个像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6280509/

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