如何根据返回的行数为tableView设置动态高度?

时间:2017-01-12 15:23:11

标签: ios swift2 tableview

我想根据返回的行数设置tableview的高度。

这就是我正在做的事情

override func viewDidLoad() {
        super.viewDidLoad()

        let height: CGFloat = self.contactListTableView.rowHeight
        let h  = Float(height) * Float(contactDbData.count)

        if(h > 445.0)
        {
            self.contactListTableView.frame = CGRectMake(0, 50, self.contactListTableView.frame.size.width, 445)
        }
        else
        {
            self.contactListTableView.frame = CGRectMake(0, 50, self.contactListTableView.frame.size.width, CGFloat(h))

        }
        contactListTableView.delegate = self
        contactListTableView.dataSource = self

    }

假设我的行高为70并获得3行,这意味着表高度应为3 * 70 = 210。

我应该如何实现这一目标?

0 个答案:

没有答案