更改UITableViewCell大小会给我一个错误

时间:2015-07-01 03:36:59

标签: ios objective-c uitableview animation autolayout

我在UIView中有一个static UITableViewCell。我向constraint添加了高度view。我认为,动画views高度变化的正确方法是这样的:

self.myViewsHeightConstraint.constant = 100; // Coming from 0 and vice versa
[UIView animateWithDuration:0.3f animations:^{
    [self.view layoutIfNeeded];        
}];

我将tableView行高设置为:

tableView.estimatedRowHeight = 40;
self.tableView.rowHeight = UITableViewAutomaticDimension; 

现在我需要更新cells高度。所以我认为begin / endUpdate是合适的。当veiwcell动画显示其高度发生变化时,它们不会同步,因为它们不会在完全相同的时间内制作动画,我会收到以下警告:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7f8d62d15670 V:[tagResultTableView:0x7f8d62d901a0(107)]>",
    "<NSLayoutConstraint:0x7f8d62cea010 tagResultTableView:0x7f8d62d901a0.top == UITableViewCellContentView:0x7f8d62d8fd50.topMargin - 8>",
    "<NSLayoutConstraint:0x7f8d62cf0760 V:[tagResultTableView:0x7f8d62d901a0]-(8)-[UILabel:0x7f8d62d2e2e0'Limit: Up to 5 tags']>",
    "<NSLayoutConstraint:0x7f8d62cf0800 UILabel:0x7f8d62d2e2e0'Limit: Up to 5 tags'.bottom == UITableViewCellContentView:0x7f8d62d8fd50.bottomMargin>",
    "<NSLayoutConstraint:0x7f8d62f726d0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f8d62d8fd50(32)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8d62d15670 V:[tagResultTableView:0x7f8d62d901a0(107)]>

如果我的逻辑是正确的,我怎么能在同一时间为它们设置动画。或者我如何设置它们的动画,以便我不会收到错误?

2 个答案:

答案 0 :(得分:1)

如果你想确保Cell保持静态而不改变实现这个方法:

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

内部有一个返回语句,返回单元格高度的最终值。

答案 1 :(得分:0)

你有高度调整功能,我不知道你的确切需要,但如果我想改变高度,我会在函数内添加一个if语句,以测试它是否与index作为您想要变大的项目。刷新列表将调整元素大小而不会导致其他问题。我也放弃了对细胞视图的约束。在我计划调整元素大小的时候,我没有使用大小限制。