2015-03-24 39 views
0

我知道這是一個問題,有人可能會回答,但我還找不到解決方案。是否可以使用Swift更改iOS 7中的靜態單元格高度?

我試圖用斯威夫特代碼更改靜態細胞的HIGHT。我正在使用此方法 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat

但是,單元格大小不會根據標籤的內容而改變。這是我的:

@IBOutlet weak var testDetailsLabel: UILabel! 
@IBOutlet weak var testDetailsCell: TestDetailsTableViewCell! 

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

    if indexPath.section == 1 && indexPath.row == 0 { 
     self.testDetailsCell.descriptionLabel?.text = self.test?.details 
     self.testDetailsCell.setNeedsLayout() 
     self.testDetailsCell.layoutIfNeeded() 
     self.testDetailsCell.bounds = CGRectMake(0.0, 0.0, tableView.bounds.width, self.testDetailsCell.bounds.height) 
     self.testDetailsCell.setNeedsLayout() 
     self.testDetailsCell.layoutIfNeeded() 

     let size = self.testDetailsCell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) as CGSize! 

     return size.height + 1 
    } 

    return super.tableView(tableView, heightForRowAtIndexPath: indexPath) 
} 

任何機構知道是否有可能改變靜態細胞的高度尺寸?

也許約束的問題呢?我有雙方約束,頂部,底部和高度> =約束。

回答

1

我斟酌着這隻昨晚也。我在iOS8上的發展,所以我道歉,如果這不工作,IOS 7,但我所做的就是連接一個IBOutlet對錶本身,在我viewDidLoad中()方法用下面的代碼:

@IBOutlet var logInTable: UITableView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     logInTable.rowHeight = 50 //Make table cells fixed height 

} 

我希望這幫助。

謝謝

相關問題