Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 Today Widget fit height of UITableView using Auto Layout

I'm working with a Today Extension, displaying a UITableView. There are only a couple of items, but I get empty rows as well.

I'm able to use Auto Layout with an outlet constrain on the table view height to resize the table to fit only the rows with content.

What I'm not able to do is make the widget resize to wrap the table view. At the moment I'm left with a properly sized table and a lot of empty space.

like image 212
mokagio Avatar asked Sep 11 '14 06:09

mokagio


1 Answers

If you want the widget's controller to be the height of the tableView, do this:

self.preferredContentSize = self.tableView.contentSize;

You should set this each time you reload your data of the tableView and the height would change. You don't have to worry about the contentSize's width because the system ignores it.

To correct your answer above, you would need to add:

self.view.translatesAutoresizingMaskIntoConstraints = NO;

That should fix the constraint warnings.

like image 91
Henry T Kirk Avatar answered Oct 25 '22 22:10

Henry T Kirk