gpt4 book ai didi

iphone - Autolayout 不适用于可重用的 tableview 单元格

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

我正在尝试使用 Autolayout 和 Interface Builder 创建自定义 TableViewCell。我像这样在 viewDidLoad 中设置我的单元格:

[tableView registerNib:[UINib nibWithNibName:@"BChatCell" bundle:Nil] forCellReuseIdentifier:@"ChatCell"];

然后我像这样使单元格出队:

- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:        (NSIndexPath *)indexPath {
BChatCell * cell = [tableView_ dequeueReusableCellWithIdentifier:@"ChatCell"];
return cell;
}

当 TableView 首次加载时,它会正确加载:

enter image description here

但是,在表格滚动后,Autolayout 中断:

enter image description here

约束条件如下:

enter image description here

如有任何帮助,我们将不胜感激。

最佳答案

我遇到了完全相同的问题。把我逼疯了,因为在细胞被重复使用之前一切看起来都很棒。

我发现调整大小的 View 不是单元格本身(始终是屏幕宽度),而是我拥有的内部内容 View 。您可以使用 NSLog(@"%@", [theView constraints]); 在任何 View 上打印所有约束,这有助于调试

也试过无果:

  • 将所有重要的 View 和 subview 设置为 translatesAutoresizingMaskIntoConstraints=NO

  • -(void)prepareForReuse 中手动设置边界

  • 调用setNeedsUpdateConstraints

问题是我将我的内部卡片 View 命名为 “contentView”,它已经是 UITableViewCell 中的命名 View 。更改它可以解决调整大小的问题。

关于iphone - Autolayout 不适用于可重用的 tableview 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18934758/

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