2015-06-10 37 views
0

在我的應用程序中,我試圖在UITableView中顯示Mkmapview。當我點擊單元格時,它必須展開並顯示地圖。然後,如果我點擊另一個單元格,它應該再次展開並顯示圖庫視圖,以前的單元格必須摺疊並且應該隱藏地圖。在UItableview中如何動態地展開和摺疊特定的TableviewCell

在此先感謝,

+0

我使用Ios8和xcode 6.2.3 objctive C –

回答

1

你要跟蹤的展開/摺疊單元的狀態(或高度)。然後在tableView:heightForRowAtIndexPath:報告那個高度。然後添加下面的代碼來觸發調整大小。

[self.tableView beginUpdates]; 
[self.tableView endUpdates]; 

例如:

- (void)toggleMapCell { 
    _mapCellExpanded = !_mapCellExpanded; 
    if (_mapCellExpanded) 
     _mapCellHeight = 200.0; 
    else 
     _mapCellHeight = 44.0; 
    [self.tableView beginUpdates]; 
    [self.tableView endUpdates]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if ([indexPath isEqualTo:_mapCellIndexPath]) 
     return _mapCellHeight; 
    else 
     return 44.0; 
} 

如果你有重新佈局單元格的內容。我認爲最好的地方是在電池的layoutSubviews中做到這一點。