内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
要添加的代码
- (IBAction)onAdd:(id)sender { count ++; [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom]; }
解决方案是子类UITableView并在layoutSubview中设置contentSize:
- (void)layoutSubviews { [super layoutSubviews]; CGSize contentSize = self.contentSize; contentSize.width = self.bounds.size.width; self.contentSize = contentSize; }