lemontwist
lemontwist

Reputation: 301

UITableView won't resize properly until I rotate device

I am setting the frame of a UITableView in viewDidLoad, also after the device is rotated to ensure that it remains in the proper location. Here is my code:

- (void)viewDidLoad
{
    [self setItemBoundaries];
}

- (void) setItemBoundaries {
    if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
        self.raceTable.frame = CGRectMake(20,502,728,472);
    }
    else {
        self.raceTable.frame = CGRectMake(20,20,492,708);
    }
}

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [self setItemBoundaries];
}

However when the app loads, the table is sized incorrect (only on landscape mode): enter image description here

After rotating through portrait back to landscape, it looks fine: enter image description here

What am I doing wrong?

Upvotes: 0

Views: 266

Answers (2)

holex
holex

Reputation: 24041

put the -setItemBoundaries into the -viewWillAppear: method

- (void)viewDidLoad
{
    // [self setItemBoundaries];
}

and:

- (void)viewWillAppear:(BOOL)animated {
    [self setItemBoundaries];
}

and violá...

Upvotes: 1

Snips
Snips

Reputation: 6753

did...

...is called after the rotation has occurred, and therefore possibly after the table has been drawn.

Try,

willRotateFromInterfaceOrientation

...to set the new boundaries before the table is redrawn.

Upvotes: 0

Related Questions