【发布时间】:2013-01-02 09:53:32
【问题描述】:
我创建了一个带有自定义UITableViewCell 的UITableview。UITableViewCell 包含UILabels,并且我根据单元格高度计算了每个单元格的高度。但是我怎样才能获得 tableview 高度?因为基于在 tableView 的高度上我需要计算
滚动视图的高度
单击按钮时,我创建了这样的UITableView:
-(IBAction)btnClicked:(id)sender
{
self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0,150,327,[arr5 count]*205) style:UITableViewStylePlain];
self.tableView.delegate=self;
self.tableView.dataSource=self;
self.tableView.scrollEnabled = NO;
[self.view addSubview:self.tableView];
float fscrview = 150 + self.tableView.frame.size.height + 20;
testscroll.contentSize=CGSizeMake(320, fscrview);
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *city1 = city.text;
UIFont *font = [UIFont fontWithName:@"Helvetica" size:14.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize bounds = [city1 sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
//similarly calculated for all
return (CGFloat) cell.bounds.size.height + bounds.height+bounds1.height+bounds2.height+bounds3.height+bounds4.height+bounds5.height;
}
我可以通过这个获得 tableViewCells 的高度。之后如何计算/设置 tableView 的整体高度?
以及如何根据tableView的row/height计算ScrollView的高度?
【问题讨论】:
-
你已经根据单元格高度计算出每个单元格的高度了吗?
-
是的,我计算了每个单元格的高度。我需要根据每个单元格的高度获取整体的tableview高度。?
-
@Sindhia 我想你想设置 TableView 的高度,它的 contentdata 大小意味着总单元格,然后在滚动视图中添加这个 tableview 的完整大小.. 所以使用下面我的答案。 .
标签: iphone xcode uitableview