簡體   English   中英

一個視圖中的兩個表視圖 controller 表視圖的高度應等於其內容

[英]Two tableviews in one view controller and height of tableviews should be equal to its content

我是一個新的應用內 ios 開發。 我正在嘗試獲得這樣的用戶界面:-

在此處輸入圖像描述

這里有兩種類型的表格附有一個表格視圖。 這個設計在安卓。

我嘗試在 IOS 中使用自定義 header 並在 header 中設置另一個表視圖。 像這樣:-

在此處輸入圖像描述

並設置這樣的代碼: -

override func viewWillLayoutSubviews() {

    secondview?.frame.size = CGSize(width: tableViews.frame.width, height: secondtableViews.contentSize.height + 50 + tableViews.contentSize.height)
    secondview.layer.masksToBounds = true
}




func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if tableView == tableViews {
        debugPrint(" first")
         return 50
    }else{
        debugPrint(" second")
        return 50
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if tableView == tableViews {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell
        cell.textLabel?.text = "skdjfhkjfhjkshfkhsdkfhjsd"
        return cell
    }else{
        let cell = tableView.dequeueReusableCell(withIdentifier: "gcell")! as UITableViewCell
        cell.textLabel?.text = "skdjfhkjfh    jkshfkhsdkfhjsd"
        return cell
    }
    return UITableViewCell()
}

我改變了主表視圖的高度。 根據表格視圖的內容,它在某些部分高度上起作用,並且第二個和第二個顯示的第一個表格的數據顯示在第一個上。 任何人都可以幫助我解決這個設計問題。

你應該 go 一個帶有兩個部分和兩個不同類型單元格的表格視圖......!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM