【发布时间】:2017-12-17 18:19:35
【问题描述】:
我可以根据 tableview 内容高度给出滚动视图的高度,但有时滚动视图高度不滚动,有时滚动视图高度给我基于 tableview 的完美高度,我很困惑它没有每次都给我我运行应用程序,它没有根据 tableview 给出完美的高度。在我的两个 tableview 数据都来自 Web 并且由于 Internet 速度慢,我没有根据 tableview 高度获得滚动视图高度,所以它在 tableview 中加载数据很慢??
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == tableview{
let cell = tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! noticeTableViewCell
let noticedata = notices[indexPath.row]
cell.noticeText.text = noticedata.notice
tableviewheightConstraint.constant = tableView.contentSize.height
// scrollview.contentSize = CGSize(width: self.view.frame.size.width, height: tableview.frame.origin.y + tableView.contentSize.height )
return cell
} else {
let cell = pendingtableview.dequeueReusableCell(withIdentifier: "pendingbillcell", for: indexPath) as! PendingbillTableViewCell
let getdata = pendingbillsdata[indexPath.row]
let date = getdata.date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
let dateFromString : NSDate = dateFormatter.date(from: date)! as NSDate
dateFormatter.dateFormat = "dd-MM-yyyy"
let datenew = dateFormatter.string(from: dateFromString as Date)
cell.billnotext.text = getdata.Billno
cell.datetext.text = datenew
cell.amounttext.text = getdata.amount
cell.statustext.text = getdata.status
pendingtableviewheightConstraint.constant = tableView.contentSize.height
scrollview.contentSize = CGSize(width: self.view.frame.size.width, height: pendingtableview.frame.origin.y + tableView.contentSize.height)
return cell
}
}
或者我在代码中遗漏了一些我没有得到的东西,这个问题可以解决吗?
【问题讨论】:
-
为什么你想改变滚动视图的高度而不是它的内容大小?
标签: ios uitableview swift3 uiscrollview