开发者

Different height for alternative cell in UITableView

开发者 https://www.devze.com 2023-01-12 21:59 出处:网络
How to make a alternate cel开发者_JAVA技巧l with a different height? I need height for cell1 is 60 and cell2 is 30....

How to make a alternate cel开发者_JAVA技巧l with a different height?

I need height for cell1 is 60 and cell2 is 30....

how can i do this?

Thanks in advance.


you can set the height of cell from the delegate method of table view

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.row==0)
     {
        return 60;
     }
     else if(indexPath.row==1)
     {
        return 20;
     }
}

and so on....

Happy coding....


Use the modulus operator and you dont need an if case for every row index :)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.row % 2 == 0)
     {
        return 60;
     }
     else
     {
        return 30;
     }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号