Janna Janna -3 years ago 70
Objective-C Question

iOS - Where to resize UITableView in order to fit content when created in a custom View and not ViewController

I'm facing an issue while working on

UITableView
. I am working with Google Map iOS SDK, and I created a custom View in order to implement my own
Marker Info Window
.

So I added the
UITableView
in my
UIView
, but I don't know where to resize it so that it fits its content.

I have set my
tableViewHeightConstraint
, and now I want it to fit the content of the tableView.

Code like this :

self.tableViewHeightConstraint = self.tableView.contentSize.height


I don't know where in a custom
UIView
I can do it, I don't have
viewWillAppear
or
viewDidLoad
method.

And if I call it in the View's init method, it will probably be called too early, while its content isn't drawn yet.

EDIT:

Something like this ?

-(void) layoutSubviews {
self.heightTableView.constant = self.tableViewRisk.contentSize.height;
}

Answer Source

Try implementing the code self.tableViewHeightConstraint = self.tableView.contentSize.height in the views layoutSubviews() function

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download