2016-09-29 126 views
0

我有填充有其已經由XIB(自動佈局)。該細胞根據響應由變化的大小的多個標籤的圖像等和大小的創建的自定義細胞一個UITableView我們從api中獲得。我一直在動態地嘗試硬盤集高度。我正在使用以下方法。如何設置定製UITabelview細胞的動態高度在SWIT

func createTabelView() 
    { 
    let nib = UINib(nibName: "DBEventCell", bundle: nil) 
     self.eventTabelVew.registerNib(nib, forCellReuseIdentifier: Constants.CELL_IDENTIFIER) 

     self.eventTabelVew.estimatedRowHeight = 200 
     self.eventTabelVew.rowHeight = UITableViewAutomaticDimension 
     self.eventTabelVew.separatorStyle = .None //UITableViewCellSeparatorStyle.SingleLine; 
     self.eventTabelVew.separatorColor = UIColor.clearColor(); 
     self.eventTabelVew.backgroundColor = UIColor.whiteColor(); 

     self.eventTabelVew.setNeedsLayout() 
     self.eventTabelVew.layoutIfNeeded() 
    } 


func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
    { 
    return UITableViewAutomaticDimension 
    } 
func tableView(tleView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 

     return UITableViewAutomaticDimension 
    } 

但這不working.Please做幫助,因爲我是從過去的幾天裏最後擊中。 在此先感謝

回答

0

我認爲你不需要這個功能

func tableView(tleView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 

    return UITableViewAutomaticDimension 
} 

還應該檢查你的自動佈局約束和調整UI組件的屬性,使其合同或與內容擴大也檢查本教程

https://www.appcoda.com/self-sizing-cells/

+0

IF刪除此功能estimatedHeightForRowAtIndexPath還是問題依舊一樣,我也跟着教程的「https://www.appcoda.com/self-sizing-cells/」,但它確實沒有工作 –