<分区>
标签 ios uitableview
<分区>
当从 super View 中删除 subview 时,我想根据数组中要填充到 TableView 中的项目的大小来刷新 TableView 并调整其大小。我通过创建一个框架来做到这一点,该框架将每个增加的项目的高度增加 50。这是我的代码
- (IBAction) doneAddingUsers:(id)sender {
[self.crewTable setHidden:NO];
[self.crewTable reloadData];
self.crewTable.frame = CGRectMake(self.crewTable.frame.origin.x, self.crewTable.frame.origin.y, self.crewTable.frame.size.width, [crewArray count]*50);
NSLog(@"height: %f", crewTable.frame.size.height);
[self.view bringSubviewToFront:self.crewMembersView];
[self.crewMembersView removeFromSuperview];
}
在日志中它显示了正确的高度,但在 UI 中它似乎没有改变 TableView 的高度。我也禁用了滚动
提前致谢
最佳答案
您可以这样做,而不是在 doneAddingUsers: 中设置框架:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int count = [crewArray count];
//Set the height of the tableview
CGRect frame = self.tabPackageList.frame;
frame.size.height = (count * 50);
[self.tabPackageList setFrame:frame];
// Return the number of rows in the section.
return count;
}
关于ios - UITableView 的高度未以编程方式更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15221832/