ios - 更改 UITableViewCell 大小给我一个错误

标签 ios objective-c uitableview animation autolayout

我在 static UITableViewCell 中有一个 UIView。我在 view 中添加了一个高度 constraint。我认为,为 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)]>

如果我的逻辑是正确的,我怎样才能在完全相同的时间为它们制作动画。或者如何为它们设置动画,以免出现错误?

最佳答案

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

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

并且在里面有一个 return 语句,返回单元格高度的最终值。

关于ios - 更改 UITableViewCell 大小给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31152124/

相关文章:

ios - 如何使用 CGRectEdge 来建立矩形的边?

ios - 支付成功后快速获取stripe charge id

UIScrollView中的iOS UITextField没有响应

Objective-c 使用 CharacterAtIndex

ios - 单元格不显示

ios - 无法转换 swift 类型的值

android - "Facebook Login integration"成功提交到应用中心有什么要求?

objective-c - 在 Objective-c 中从 exif 获取相机和镜头

ios - 从 Objective C 中的文件中读取字节数组

iphone - UITableView - 延迟加载联系人图像