2012-11-29 132 views
0

我需要自动调整UIScrollView的高度。实际上,我的ScrollView在UIView中。 在UIView中我有一个标签,UIButton,textField的静态大小。现在,当按钮被点击时,一些数据被加载到UITableView中。根据数组中的对象的数量,tableView中的数据是动态的。ScrollView根据UIView中的内容自动调整其高度?

总结: 在viewLoad only label,textField,button gets loaded。buttonClick tableView被加载后。

所以我需要调整滚动视图的高度,根据该criteria.But没。

-(IBAction)buttonClick 
{ 

       [testscroll setScrollEnabled:YES]; 
       [testscroll setContentSize:CGSizeMake(320,90+[array count]*180)]; 
       [self.view addSubview:testscroll]; 
    self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0,150,327,[array count]*180) style:UITableViewStylePlain]; 
       self.tableView.delegate=self; 
       self.tableView.dataSource=self; 
       self.tableView.rowHeight=180; 
       self.tableView.scrollEnabled = NO; 
       [self.view addSubview:self.tableView]; 
       [tableView release]; 

} 

我不能用C d添加滚动视图按钮click..How我能怎么做呢?

+0

看来你已经设置滚动视图的内容大小,所以究竟是什么你的问题。什么不适用于上面的代码?滚动视图的内容是什么?它滚动吗? – sergio

+0

我需要的是按钮单击我需要自动调整ScrollView.But的高度,但ScrollView不会添加nd我无法滚动 – Honey

回答

0

试试这个波纹管代码..

self.tableView.frame=CGRectMake(self.tableView.frame.origin.x, 150, self.tableView.frame.size.width, self.tableView.frame.size.height); /// you can set self.tableView.contentSize.height for set dynamic height of table with data .. 

    float fscrview = self.tableView.frame.origin.y + self.tableView.frame.size.height + 20; 
    yourScrollView.contentSize=CGSizeMake(320, fscrview); 
相关问题