Domanda

In my app I've got a view controller whose view is simply an UITableView. This table has an header which is a custom UIView whose size can change depending on the data the view controller is being passed. There's AutoLayout used in both constraining the table to the view controller's view and inside the header view (an image, views and a couple of labels).

Upon setting the table's header I'm binding the relevant data and asking the system to calculate the size whose then set back in the custom view (see below).

On my Storyboard I have the ViewController size (in Simulated Metrics) to Inferred yielding a view size of 320 x 480.

In this scenario if I run the app on iPhone 4 the header's contents fit perfectly. If I run it on the iPhone 5 there are "spaces" between the contents in the labels (think of an UILabel with a 320x200 and just a sentence centered in the middle) and the table's headers overrun the first table cell.

The code I'm using to set the header is the following:

- (void)initTable
{
  MyCustomHeaderView *headerView = [[MyCustomHeaderView alloc] init];
  headerView.data = self.myRelevantData;
  headerView.delegate = self;
  [headerView bindData];
  CGSize size = [headerView systemLayoutSizeFittingSize:UILayoutFittingExpandedSize];

  CGRect frame = headerView.frame;
  frame.size = size;
  headerView.frame = frame;

  self.table.tableHeaderView = headerView;
}

The code in bindData is like the following:

if(IsEmptyString(self.data.aText))
{
    self.titleLabelTopConstraint.constant = 0.0;
    self.titleLabel.text = nil;
}
else
{
    self.titleLabelTopConstraint.constant = 3.0;
    self.titleLabel.text = self.data.aText;
}

I appreciate any help you can provide.

A couple of screen shots, as requested.

Here's the iPhone 4 (Good):

enter image description here

...and the iPhone 5 (Bad):

enter image description here

È stato utile?

Soluzione

It seems that this was a non-trivial issue. Today, running iOS7.1 you can find a similar problem on Settings > General > Usage. If you are without network connection you will experience the same problem. See the image below.

I ended up converting the header view to a cell and having multiple cell types on the table. This is probably something I should have done to begin with.

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top