【发布时间】:2015-07-18 20:21:17
【问题描述】:
编辑
从头开始构建一个新的示例项目,动态 tableview 单元格高度可以完美运行。然后,我尝试通过将我的项目缩减到最低限度来进行复制,但它仍然损坏(前几个单元格有问题)。为工作和不工作的例子附加完整的项目。项目/代码实际上看起来 99% 相同,而且为了我的爱,我无法弄清楚 1% 的差异在哪里。唯一突然出现在我身上的是我使用了不同的尺寸等级(wAny hAny vs wCompact hRegular,但我无法想象这会做任何事情,因为我只在纵向进行测试
工作项目:
不工作的项目:
WORKING (new project from scratch):
https://drive.google.com/file/d/0B_EIkjmOj3ImWXZjVFZMYXZmVGc/view?usp=sharing
NOT WORKING (my project, cleaned up to it's bare minimum)
https://drive.google.com/file/d/0B_EIkjmOj3ImMGRNOXU2RlNkWEk/view?usp=sharing
已经浏览了网络试图了解发生了什么,但由于某种原因,我的单元格高度不正确,直到我滚动经过原型单元格。
初始加载时:
滚动经过每个单元格后:
背景颜色:
cell.postTextLabel.backgroundColor = [UIColor orangeColor];
subView.backgroundColor = [UIColor blueColor];
contentView.backgroundColor = [UIColor brownColor];
这里没有做任何太花哨的事情:只是一个原型单元格、一个子视图和三个标签(用户名、时间戳、文本)。
下面的屏幕截图突出显示了我在 Storyboard 中的限制:
我从 Parse 中提取数据,并在设置 tableView 布局时重新加载我的数据
[self.tableView setNeedsLayout];
[self.tableView layoutIfNeeded];
[self.tableView reloadData];
最后是我的cellForRowAtIndexPath 方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self postCellAtIndexPath:indexPath];
}
- (UITableViewCell *)postCellAtIndexPath:(NSIndexPath *)indexPath {
static NSString *PostCellIdentifier = @"PostCell";
PostCell *cell = (PostCell *)[self.tableView dequeueReusableCellWithIdentifier:PostCellIdentifier forIndexPath:indexPath];
[self configurePostCell:cell atIndexPath:indexPath];
[cell setNeedsLayout];
[cell layoutIfNeeded];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
return cell;
}
【问题讨论】:
-
我也遇到过这个问题。我的回答有帮助吗,stackoverflow.com/questions/27787552/…
-
不,不幸的是,这对我来说是不行的。添加到我的自定义单元格中,结果相同
-
你解决了吗?我有同样的症状。
-
我做了 - 结果我的问题非常具体,但我只需将我的尺码等级更改为 wAny 和 hAny
标签: ios objective-c uitableview autolayout uistoryboard