Dynamic height of table is not set

前端 未结 3 1476
迷失自我
迷失自我 2021-01-21 22:28

I am trying to set dynamic height of table. But it is not working when I log height of table it is showing me dynamic height but not set to actual table.

Here is my code

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 23:03

    To set the height for row you need to set

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return rowHt[indexPath.row];
    }
    

    The each row can have different height only if you set it at

    heightForRowAtIndexPath

    for that you need to select the corresponding rows from

    indexPath.row

    If you are setting your tabelView from code it would look something like this

    @property(nonatomic, strong)    UITableView     *table_sender;
    
    self.table_sender = [[UITableView alloc]  initWithFrame:frameTable style:UITableViewStylePlain] ;
        self.table_sender.dataSource = self;
        self.table_sender.delegate = self;
    

    where rowHt is a array of collection of height for each rows

提交回复
热议问题