当我尝试使用下面的代码更新表**UITableview**
时,单元格会变小。我想知道是否有人遇到过同样的问题,并且知道为什么会这样。
NSMutableArray* indexPaths = [[NSMutableArray alloc] init];
for (int i = 20; i < 20 + 20; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimationBottom)];
[self.tableView endUpdates];
....
最佳答案
@CreativityKills。
如果您的自动版式已启用,请尝试在添加行之后添加以下方法。如果这是自动布局的问题,可能会对您有所帮助。
NSMutableArray* indexPaths = [[NSMutableArray alloc] init];
for (int i = 20; i < 20 + 20; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimationBottom)];
[self.tableView endUpdates];
[self adjustHeightOfTableview];
- (void)adjustHeightOfTableview
{
CGFloat height = self.tableView.contentSize.height;
CGFloat maxHeight = self.tableView.superview.frame.size.height - self.tableView.frame.origin.y;
// if the height of the content is greater than the maxHeight of
// total space on the screen, limit the height to the size of the
// superview.
if (height > maxHeight)
height = maxHeight;
// now set the height constraint accordingly
[UIView animateWithDuration:0.25 animations:^{
self.tableViewHeightConstraint.constant = height;
[self.view setNeedsUpdateConstraints];
}];
}
希望这对您有所帮助。