iosuiviewcontrollernibloadview

view frame in -loadView


A view in a view controller created using a nib has its frame at {0, 64, 320, 416}, origin starting right below the nav bar. In -loadView without a nib however, the view with the same frame is 44 pt off despite having the same frame (origin=(x=0, y=64) size=(width=320, height=416)), origin starting below the status bar, under the nav bar. Why is this and how can I match the nib behavior?

-(void)loadView
{
    CGRect f = EPFrame;
    if(self.navigationController)
    {
        f.size.height -= self.navigationController.navigationBar.bounds.size.height;
        f.origin.y += self.navigationController.navigationBar.bounds.size.height;

    }
    UIView *base = [[UIView alloc]initWithFrame:f];
    base.backgroundColor = [UIColor clearColor];
    self.view = base;

}

Solution

  • There is no need, in this case, to implement the loadView method. By default the view controller will get an empty view. This view will be autosized to fit its container.