1

After trying this to dynamically resize my UITableView according to its contents size and failing:

    self.tableViewPairedDevices.sizeToFit()

I tried this which worked fine as long as my Today Widget is tall enough to show it entirely:

    var frame:CGRect = self.tableViewPairedDevices.frame
    frame.size.height = self.tableViewPairedDevices.contentSize.height
    self.tableViewPairedDevices.frame = frame

My next challenge was to get my iOS 8 Today Widget to resize according to the UITableView size, which I almost solved with:

    self.preferredContentSize = self.tableViewPairedDevices.contentSize;
    self.tableViewPairedDevices.setTranslatesAutoresizingMaskIntoConstraints(false)

The problem is that only one of them works at a time, if the UITableView gets resized, the extension's view doesn't, if I comment out the code that resizes the UITableView, the Today Extension gets resized successfully (the weird thing is that it knows what size the UITableView should be, even though the UITableView itself hasn't been resized) but the UITableView doesnt.

Any suggestions on how to achieve both things?

Thanks a lot!

Lee Andrew
  • 798
  • 7
  • 28

2 Answers2

2

I was able to make the above code work perfectly by disabling AutoLayout on the Extension's view

Lee Andrew
  • 798
  • 7
  • 28
0

Don't forget UITableView has a Scroll inside. You need to define the height somehow.

I add a height constraint to the UITableView and then I updated that value to the contentSize.height

And that works.

Joel
  • 511
  • 5
  • 8