2010-08-20 39 views

回答

4

可以从表视图

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

等的委托方法设置单元格的高度....

快乐编码....

2

使用模运算符并且您不需要每行索引的if情况:)

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

indexPath.row%2 == 0可以替换为!(indexPath.row&1) – 2010-08-20 08:43:12

+2

return 60 /(indexPath.row&1 + 1);但请记住,以后总会有人在阅读你的代码。 – Eiko 2010-08-20 08:52:10

相关问题