设置单元格高度给我错误

编程入门 行业动态 更新时间:2024-10-11 01:15:47
本文介绍了设置单元格高度给我错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 UITableViewCell 中有一个 UIView 。我正在尝试通过动画更改视图的高度。这是我所做的:

I have a UIView in a UITableViewCell. I'm trying to change the height of the view with an animation. Here is what I did:

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

唯一的是,它位于 tableView 。所以这就是我为 heightForRow ... 做的事情:

The only thing is, it's in a tableView. So here's what I did for the heightForRow...:

return self.myViewConstraint.constant == 0 ? 74 : 174;

现在我需要更新 tableView ,所以我插入了 animateWithDuration :

Now I need to update the tableView, so I inserted in animateWithDuration:

[self.tableView beginUpdates]; [self.tableView endUpdates];

因为我在单元格内有其他东西,因此约束变得混乱,而单元格的高度却处于动画状态。如何在不弄乱约束的情况下更新单元格的高度? (我想要个单元格的高度进行动画处理。)

Because I have other things inside the the cell, so the constraints get messed up while the cells height is animating. How can I update the cells height without getting the constraints messed up? (I want the cells height to animate.)

这是我得到的警告。 (一切正常,但我只想删除警告。)

Here is the warning I get. (Everything works fine, but I just want to remove the warning.)

编辑,我做了一些更改,现在出现此错误:

Edit I changed it a bit, and I now get this error:

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)]>

推荐答案

这里是一个示例。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return self.myViewConstraint.constant == 0 ? 74 : 174; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ReuseID]; if (!cell) { cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ReuseID]; } if (self.myViewConstraint.constant != 0) { [cell doAnimation]; } return cell; }

更多推荐

设置单元格高度给我错误

本文发布于:2023-11-23 01:07:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:给我   单元格   高度   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!