当我尝试使用下面的代码更新我的表**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];
...
答案 0 :(得分:3)
@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];
}];
}
希望这可以帮助你。
答案 1 :(得分:1)
可能你没有给UITableViewDelegate方法实现:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return 44.0;//your default row height
}