大佬教程收集整理的这篇文章主要介绍了iphone – 获取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; }
我能够通过this获取tableViewCells高度.在此之后,如何计算/设置整个tableView的高度?
并且如何根据tableView的行/高度来计算ScrollView的高度?
我想你想设置整个tableview的内容大小,然后设置与UITableView的scrollview大小相关的内容,并使用下面的代码…
在UITableView中添加数据或reloadData后,只需设置下面的代码..
yourTableView.frame = CGRectMake(yourTableView.frame.origin.x,yourTableView.frame.origin.y,yourTableView.frame.size.width,yourTableView.contentSize.height); float ftbl = yourTableView.frame.origin.y + yourTableView.contentSize.height + 15; yourScrollView.contentSize=CGSizeMake(320,ftbl);
更新:
self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0,[arr5 count]*205)style:UITableViewStylePlain]; self.tableView.delegate=self; self.tableView.datasource=self; [testscroll addSubview:self.tableView]; /// add this tableview in scrollview not in self.view [self.tableView reloadData]; self.tableView.frame = CGRectMake(self.tableView.frame.origin.x,self.tableView.frame.origin.y,self.tableView.frame.size.width,self.tableView.contentSize.height); float ftbl = self.tableView.frame.origin.y + self.tableView.contentSize.height + 15; testscroll.contentSize=CGSizeMake(320,ftbl);
以上是大佬教程为你收集整理的iphone – 获取UITableView的高度全部内容,希望文章能够帮你解决iphone – 获取UITableView的高度所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。