2012-07-03 59 views
-3

我有一个简单的问题,无法对其进行排序。我的应用程序中有一个UITableView。有3个部分,每个部分有3个行。UITableView单元格的高度

我想增加第一部分的第一个单元格的高度。我为此使用委托,但它增加了第三部分的第一个单元格的高度。

 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    if (indexPath.row == 0 && sectionValue==0) 
    {   
     sectionValue=1; 
     return 180.0;   
    } 
    else 
    { 
     return 44.0;   
    } 
} 
+0

sectionValue在viewDidLoad中设置0。 –

+1

您也必须检查'indexPath.section == 0'! (+投票,因为这个问题问了十多次!) –

+0

可能重复[iPhone + UITableView +行高](http://stackoverflow.com/questions/1635783/iphone-uitableview-row-height) – Monolo

回答

2

您可以直接使用indexPath.section -

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (indexPath.row == 0 && indexPath.section==0) 
    { 
     return 180.0; 

    } 
    else 
    { 
     return 44.0; 

    } 
} 
+0

它的工作原理,谢谢。 –

0

试试这个......

indexPath.section