Get UITableView's height

前端 未结 5 1338
终归单人心
终归单人心 2021-02-20 10:27

I have created a UITableview with custom UITableViewCell.The UITableViewCell contains UILabels and I have calculated the heig

5条回答
  •  醉话见心
    2021-02-20 10:50

    Use contentSize.height property of UITableView.

    I think you want to set the whole tableview with content size and then set the scrollview size related content of UITableView and for this use bellow code...

    After add data or reloadData in UITableView just set bellow code..

        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);
    

    UPDATE:

    self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0,150,327,[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); 
    

提交回复
热议问题