0

I have a problem with the vertical alignment of a UITextField in a TableView when using Dynamic Type to change the user-selected font sizes and weights.

Cause of my terrible English, I`ll use Screenshots: Upps, not enough reputations to post them. :-(

In my TableView with custom Cells I´m using Autolayout. But disabling Autolayout doesn´t matter for my problem. So I think this doesn´t cause it.

Everything looks fine.

When I change to "Settings" and select another the font size, after returning to the App, the UITextFields vertical Alignment had moved up by about 5 points, depending on the new Fontsize

When one [textField becomeFirstResponder], it moves into the correct position:

When I close the Form and open it again, everything is ok!!!

The source code:

in viewDidLoad

    [[NSNotificationCenter defaultCenter]
        addObserver:self
        selector:@selector(preferredContentSizeChanged:)
        name:UIContentSizeCategoryDidChangeNotification
        object:nil];

and

- (void)preferredContentSizeChanged:(NSNotification *)notification 
{
[self.tableView reloadData];
}  

- (void) configureFonts:(DetailColumnCell *)cell 
{
cell.txtDetail.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
}

Ok, a small problem, but so it doesn´t look professional ;-)

EDIT 1

There is a Label above the TextField. The Alignment of this Label keeps fine.

EDIT 2

When in the TableView are invisible cells at the bottom, I change the Font and scroll to this previously invisible cells, these cells are fine! Is the reuse of cells the matter? But I see no way to change this...

Ulli H
  • 1,748
  • 1
  • 19
  • 32

1 Answers1

0

Urrgh, I found it after days in this article :-)

I had to add the method estimatedHeightForRowAtIndexPath and everythig is fine:

  • (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    // Do the minimal calculations required to be able to return an estimated row height that's
    // within an order of magnitude of the actual height.
    // 250 => try and error: 200.0 was enough for me at iPhone, but iPad need more
    return 250.0f;
Community
  • 1
  • 1
Ulli H
  • 1,748
  • 1
  • 19
  • 32