2012-08-06 164 views
0

是否有无论如何我可以在- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath当前单元格的高度设置高度更改以前的UITableViewCell的高度?更改heightOfPrevious UITableViewCell

UITableView中有两行。在第一行时,它将设置默认高度。当在第二行时,我想改变第一行的高度。这可能吗?如果是这样如何?

谢谢,
Bharathi。

+0

你是指当选择第一行吗? – arnoapp 2012-08-06 12:32:18

+0

编号当初始化自己... – 2012-08-06 12:34:18

+0

你能指定什么是你确切的要求。你可以找到一个替代解决方案,而不是在第二行时更改第一行高度。 – Anish 2012-08-06 12:35:26

回答

0

bharathi:

你必须重新加载表中的UITableViewdidSelectRowAtIndexPath方法。

您应该检查第二行被选中,然后重新加载所有表行,因此所有tableview delegatedatasource方法都会再次被调用。

+0

但她想在初始化期间改变高度。 – Anish 2012-08-06 12:39:14

1

如果满足要求,尝试使用布尔检查。 你可以做这样的:

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

    if (indexPath.row == 0 && !secondRowIsSynced) { 
     return otherHeight ; 
    } 
    else { 
     return defaultHeight; 
    } 
} 
+0

不,我想我没有很好地表达我的要求。 heightForRowAtIndexPath将返回当前行的高度。那很完美。以及我想改变前一行的高度......这不可能吗? – 2012-08-06 13:09:19

+0

它会建议你:尝试一下,看它是否做你想做的事情。你也可以用变量来做它(例如,你可以随时检查即将到来的行或类似的东西) – arnoapp 2012-08-06 14:28:36

0

我想你误会tableView:heightForRowAtIndexPath:被多次调用(一次为每个行的表格)。

如果你的行有不同的高度,那么你需要确定你所在的行和应该具有的高度。

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

    if (0 == indexPath.row) { 
     // This is the first row 
     height = // what ever you want 
    } else if (1 == indexPath.row) { 
     // This is the second row 
     height = // what ever you want 
    } 

    return height; 
} 

如果您稍后决定行需要一个不同的高度,然后它仍然是这个方法需要计算用于每个行正确的高度。你可以强制这个被调用,而无需重新加载tableView像这样

[tableView beginUpdates]; 
[tableView endUpdates];