0

My landscape, iPad app has a table view controller presented as popover from a bar button item.

To fit the popover to the table view size, I do this on the table view controller's code:

override func viewDidLoad()
{
    super.viewDidLoad()

    tableView.estimatedRowHeight = 44.0
    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.scrollEnabled = false
}

override func viewWillAppear(animated: Bool)
{
    super.viewWillAppear(animated)

    tableView.reloadData()   
    preferredContentSize = tableView.contentSize
}

This works fine for adjusting the popover's height to that of the table view (taking into account number of rows and height of each row).

However, if I set the label of one of the cells to a string that is too long, it will truncate (...), even though there is plenty of room on screen for the popover (and the table view) to grow further horizontally.

I could hard-code some big-enough width, like this:

override func viewWillAppear(animated: Bool)
{
    super.viewWillAppear(animated)

    tableView.reloadData() 

    var size = tableView.contentSize
    size.width = 600  
    preferredContentSize = size 
}

...but I would prefer a more dynamic and elegant solution (e.g. minimum width that fits all cells' contents).

Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
  • brother please add screenshot so i can understand more clearly – Hitesh Surani Dec 08 '15 at 06:19
  • The `label` of the table view cell reads: "OneTwoThr..." instead of "OneTwoThreeFour.". The table view and popover could still grow horizontally to accommodate it, but they don't. – Nicolas Miari Dec 08 '15 at 06:21

1 Answers1

-1

Use these for handle them dynamically

DynamicView.autoresizingMask = UIViewAutoresizing.FlexibleTopMargin .union(UIViewAutoresizing.FlexibleLeftMargin .union(UIViewAutoresizing.FlexibleRightMargin))
Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65