2012-08-06 27 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];