Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

ios - TableView Automatic Dimension Tableview Inside Tableview

I have Tableview for showing food orders placed by clients. which contains Horizontal UIStackview. In UIStackView

In UIStackview There is few one / two lined label and one UITableView which is used to show orderItems. Inner tableview has fixed height constant (greater then or equal + 750 Priority) and will be changed with content size. height and scrolling disabled.

inner tableview has two labels. and heigh is automatic Dimension

I want main tableview cell height should be increased automatically as per inner tableview items. so I apply to main tableview

    self.tblOrders.rowHeight = UITableViewAutomaticDimension
    self.tblOrders.estimatedRowHeight = 45

and In tableview cell subclass

override func awakeFromNib() {
    super.awakeFromNib()
    self.tblOrderMaster.dataSource = self
    self.tblOrderMaster.delegate = self

    self.tblOrderMaster.estimatedRowHeight = 45
    self.tblOrderMaster.rowHeight = UITableViewAutomaticDimension
    self.selectionStyle = .none
    self.layoutIfNeeded()

    self.tblOrderMaster.isScrollEnabled = false

}

Inner tableview datasource array

var orderData:[ODOrderDataMaster] = [] {
        didSet {
            self.tblOrderMaster.reloadData()
            self.layoutIfNeeded()
            self.const_Height_tblOrderMaster.constant = self.tblOrderMaster.contentSize.height
            self.layoutIfNeeded()

        }
    }

Question: When I scroll main tableview it is not correctly resized as per subitems.while initially it is showing correct.

I have almost tried everything like layoutIfNeeded. layoutSubviews. setNeedsDisplay.

I have also implemented willDisplayCell but not success.

I think issue is when I reload inner tableview. and when it is finished reload how can i inform to main tableview and how can i update height constant of inner tableview

Please let me know if anyone need more info.

I appreciate any help or suggestion

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add these 2 lines before the end of cellForRowAt in main & inner tableViews

  cell.layoutSubviews()

  cell.layoutIfNeeded()

  return cell

Also you may try add layoutSubviews method in main cell subclass and do this

  self.tblOrderMaster.layoutIfNeeded()

and in viewDidLayoutSubviews of controller of the main tableView and do this

  self.tblOrders.layoutIfNeeded()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...