gpt4 book ai didi

iphone - 自定义 UITableViewCell 宽度在 tableview reloadData 上调整大小

转载 作者:行者123 更新时间:2023-11-28 22:57:56 26 4
gpt4 key购买 nike

我有一个 UITableView,我通过 UIView 动画 block 增加它的宽度。

[UIView animateWithDuration:.5 
animations:^{
CGRect frame = myTableView.frame;
frame.size.height += 190;
myTableViewView.frame = frame;
[[myTableViewView visibleCells] makeObjectsPerformSelector:@selector(setNeedsDisplay)];
}
completion:nil];

此调用完成后,我的子类 UITableViewCells 将被重绘并调用此委托(delegate)方法。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell        forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect frame = cell.frame;
frame.size.width = tableView.frame.size.height;
cell.frame = frame;
}

没有这个,我的 UITableViewCells 就不会绘制到 UITableView 的整个宽度。我遇到的问题是当我调用 [tableView reloadData] 时。重新加载数据正在调用上面的 willDisplayCell 调用来设置正确的帧,但是当我观察 UITableViewCell setFrame 的堆栈跟踪时:另一个调用正在从私有(private) UITableView 调用对我的所有单元格调用:

 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:]

此调用将我所有可见的 UITableViewCells 的框架设置为 UITableView 的原始宽度和更小的宽度。有谁知道如何防止这种情况发生,以便我的单元格保持表格 View 的宽度?

最佳答案

我认为最好的办法是不要对 UITableViewCell 宽度施展魔法。

更好的解决方案是向单元格添加 subview 并更改该 subview 的宽度。

关于iphone - 自定义 UITableViewCell 宽度在 tableview reloadData 上调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10450286/

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