2015-12-17 34 views
0

我想以編程方式調整UITableViewCell已經被渲染後的高度。由於該單元格已被渲染,因此我無法使用tableView:heightForRowAtIndexPath:如何在UITableViewCell已經被渲染後調整大小?

如何在已經渲染後調整單元格大小?

+0

那麼你到底是怎麼做到的呢? – Nico

+1

@Nico我想我只是重新加載整個表數據。我一直想用答案中提到的動畫方法嘗試重載行,但沒有機會。 – Andrew

回答

3

您必須在tableView:heightForRowAtIndexPath:重新計算,之後您必須重新加載此單元格或致電tableViewreloadData

比如你要在第4行調整單元,且有按鈕水龍頭它來調整,就可以實現這樣的

func resizeCell() { 
    self.indexReload = NSIndexPath(section: 0, row:4) 
    self.heightYouWant = heightYouWant 
    self.tableView.reloadRowsAtIndexPaths([self.indexReload], withRowAnimation: .Fade) 
} 

而且heightForCellAtIndexPath你必須實現這樣的:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if index == self.indexReload { 
     return self.heightYouWant 
    } or { 
     //calculate normal as you want 
    } 
} 

這是我的想法。希望這個幫助!

相關問題