2016-03-30 116 views
0

我使用Xcode製作應用程序。使用自動佈局,我有一個包含在容器視圖中的tableview,它是嵌入到導航控制器中的視圖控制器的一部分。如何設置表格視圖單元格以適應標籤?

此表視圖是我的內容頁面,所以單個tableview單元格導致另一個tableview包含我想要顯示的大量信息。

我添加了UIlabel,它爲每個tableview單元格包含一段單詞,併爲各個tableview單元格設置約束。

在故事板中,看起來好像必須能夠看到所有段落。我已將行設置爲0,並自動換行。

當我運行程序時讓我們說4s模擬器,表格視圖單元格不顯示整個段落,而只是在每個段落的末尾指示「...」。

如何設置這樣的設置,使桌面視圖單元格在根據UIlabel進行字詞包裹後自動進行調整,以提供特定的手機屏幕尺寸?

PS:我是SWIFT編程新手,感謝您花時間幫助我。

回答

0

你有沒有這樣做?:

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

這是必需的自調整大小表視圖細胞。另外,請確保以下的事情:

一)UILabel行數設置爲0

二)在表格視圖單元格的自動佈局系統是正確的 - 所有的思想都是建立在各方寄託並且自動佈局可以準確地確定單元格的高度。

c)也做一個tableView.estimatedRowHeight = 75(或您的估計高度)的效率。

0

在viewDidLoad中添加這兩行方法和標籤行數爲0,不給任何高度。

func viewDidLoad() { 
    super.viewDidLoad() 

    tableView.estimatedRowHeight = 44.0 
    tableView.rowHeight = UITableViewAutomaticDimension 

} 
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell 
    //cell.customTexLabel Number 0f lines 0 and dont give height contrains just Leading,Trailing,TOP and Bottom. 
    cell.customTextLable?.text = "Here index starts from 0 which means first element can be accessed using index as 0, second element can be accessed using index as 1 and so on. Let's check following example to create, initialize and access arrays:Here index starts from 0 which means first element can be accessed using index as 0, second element can be accessed using index as 1 and so on. Let's check following example to create, initialize and access arrays:Here index starts from 0 which means first element can be accessed using index as 0, second element can be accessed using index as 1 and so on. Let's check following example to create, initialize and access arrays:" 

    return cell 
} 
相關問題