我能夠根據tableview內容高度給出scrollview的高度,但有時scrollview高度不滾動,有時scrollview高度給了我基於tableview的完美高度,我很困惑,它不會給我每一次,每當我運行的應用程序它沒有給完美的高度基於tableview。在我的兩個tableview數據都來自網絡,它是我沒有得到基於tableview高度的scrollview高度,因爲互聯網慢所以它加載數據緩慢tableview?如何根據UITableView高度動態設置UIScrollView高度?
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
}
}
或者我在代碼中遺漏了一些我沒有收到的東西,可以解決這個問題嗎?
內容的大小,爲什麼你想改變滾動視圖的高度,而不是它的contentsize? –