2011-07-13 92 views
0

我想擴大一個UITableViewCell具有這種功能,從didSelectRowAtIndexPath方法調用:崩潰的UITableViewCell在第二次點擊

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(selectedCellIndexPath != nil && 
     [selectedCellIndexPath compare:indexPath] == NSOrderedSame) 
     return 128; 
    return 43; 
} 

點擊一個細胞擴展它,點擊另一個單元坍塌到老,並擴大新的細胞。到現在爲止還挺好。但是我也想在單擊擴展單元時摺疊單元格,但不知道如何?

作爲獎勵:顯示未展開單元格的內容,與下面的單元格重疊。如何防止顯示應按摺疊單元格大小裁剪的內容?

+0

你試過cell.contentView.clipsToBounds = YES? – thelaws

回答

0

聽起來像你只需要檢查didSelectRowAtIndexPath:…,如果indexPath等於selectedCellIndexPath,然後將selectedCellIndexPath設置爲nil

您沒有提供該代碼,所以我只是猜測。

0

你也可以使用一個BOOL在你的頭聲明,然後你詮釋

-didSelectRowAtIndexPath:indexPath { 
if(your condition) { 

BOOL Selected = YES 

[tableView reloadRowAtIndexPath:indexPath] 
    } 
} 

-heightForRowAtIndexPath:indexPath { 

if(indexPath.Section == TheOneYouWant && indexPath.row == TheOneYouWant && Selected) 
return YourHeight; 
else if (indexPath.Section == TheOneYouWant && indexPath.row == TheOneYouWant && !Selected) 
return yourOtherHeight; 
}