ScrollView根据UIView中的内容自动调整其高度?

时间:2012-11-29 09:23:00

标签: iphone xcode uiscrollview

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

总结一下: 在viewLoad only标签上,textField,按钮被加载。 按钮点击后,tableView被加载。

所以我需要根据这个标准调整scrollView的高度。但是无法做到..

-(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];

}

我无法在按钮点击时添加scrollView ..我怎么能得到它?

1 个答案:

答案 0 :(得分: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);