我有一个包含表视图的视图控制器(见下面的截图)。此表视图始终恰好有3行,当单击这些行时,这些行将展开以显示更多信息。如何才能使表视图的高度始终显示这三行,而不是更多?正如您在屏幕截图中看到的,显示的是没有内容的空行。
请注意,展开的行可能包含UILabels以外的视图。
这是它在IB中的外观:

发布于 2012-10-11 01:34:29
我想你需要这样的东西
//Return number of rows in section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
[self setTableHeight];
return 3;
}
//Method which lets you calculate the height of tableView depending on your 3 cells
- (void)setTableHeight
{
if(_isRowExpanded == NO)
{
tableHeightCalculated = rowHeight * 3; // rowHeight use default 44 or ur custom
}
else
{
//You need to put some logic here to Calculate or put approx height of Expanded_Row_Height
tableHeightCalculated = rowHeight * 2 + Expanded_Row_Height;
if(tableHeightCalculated > maxHeightAllowed) //maxHeightAllowed is your current table height in snapshot
{
tableHeightCalculated = maxHeightAllowed;
}
}
tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y,
tableView.frame.size.width, tableHeightCalculated);
}发布于 2012-10-10 22:30:24
如果垂直方向上的空间比显示实际单元格所需的空间多,UITableView会插入假的空单元格。您无法真正控制此行为,最多只能将表视图的高度设置为足够小的值。
发布于 2012-10-10 22:34:52
使用要通过编程操作的任何控件的frame属性。frame还具有size和origin的两个属性。使用size属性可以操作宽度和高度,使用origin可以操作控件的x和y属性。您需要的功能可以通过以下方式完成:
CGRect frame = control.frame; //control is your UIControl
frame.size.height = 10.0; //suppose 10 is the desired height.
control.frame = frame;
希望这就是你要找的。
https://stackoverflow.com/questions/12821804
复制相似问题