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

636 Views Asked by At

I am a new in-app ios development. I am trying to get a UI like this: -

enter image description here

Here two types of tables are attached with one table view. This design in andriod.

I tried in IOS and take one table view with custom header and in the header I set another table view. Like this:-

enter image description here

And set code like this : -

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()
}

I change the height of main table view. It workes on some part height do not work according to the content of table view and the data of first table showing on second and second is showing on first. Can any one help me out from this design issue.

1

There are 1 best solutions below

0
Mian Shoaib On

you should go with one tableview with TWO sections and TWO different type of cell...!