tags:

views:

47

answers:

2

How to make a alternate cell with a different height?

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

how can i do this?

Thanks in advance.

+2  A: 

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....

Suriya
+1  A: 

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;
     }
}
willcodejavaforfood
Aleksejs
return 60 / (indexPath.row But remember, there is always someone reading your code later...
Eiko