【发布时间】:2012-05-04 13:56:14
【问题描述】:
我有一个 UITableView,我正在通过 UIView 动画块增加它的宽度。
[UIView animateWithDuration:.5
animations:^{
CGRect frame = myTableView.frame;
frame.size.height += 190;
myTableViewView.frame = frame;
[[myTableViewView visibleCells] makeObjectsPerformSelector:@selector(setNeedsDisplay)];
}
completion:nil];
此调用完成后,我的子类 UITableViewCell 将被重绘并调用此委托方法。
- (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 的堆栈跟踪时:正在从私有 UITableView 调用对我的所有单元格调用另一个调用:
-[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:]
此调用将我所有可见 UITableViewCells 的框架设置为 UITableView 的原始和更小的宽度。有谁知道如何防止这种情况发生,以便我的单元格保持表格视图的宽度?
【问题讨论】:
-
你好,在 UIView 动画块中你只是增加高度而不是宽度,如果你想增加两者都在这里申请。
标签: iphone objective-c ios uitableview