Search code examples
iosobjective-cuinavigationcontrollerxibpresentviewcontroller

Why is my initWithNibName method returning a nil view?


I'm calling this method when trying to present a new view controller. The commented out lines are the other things I've tried with no success.

-(void)presentMailBoxViewController{
    TPMailBoxViewController* mailBoxViewController=[[TPMailBoxViewController alloc]initWithNibName:@"TPMailBoxViewController" bundle:nil];
    [self.navigationController pushViewController:mailBoxViewController animated:YES];
    //[self.navigationController presentViewController:mailBoxViewController animated:YES completion:NULL];
    //[self presentViewController:mailBoxViewController animated:YES completion:NULL];
}

I've set the file owner as my corresponding view controller.

enter image description here

I've even linked the view object of my xib into my view controller as a property.

enter image description here

But, when I break on [self.navigationController pushViewController:mailBoxViewController animated:YES];

The view property of the view controller is nil. What gives?


Solution

  • A project clean and this one line change in my presentMailBoxViewController fixed my issue. Still would like to know why though. Thanks everyone!

    -(void)presentMailBoxViewController{
        TPMailBoxViewController* mailBoxViewController=[[TPMailBoxViewController alloc]initWithNibName:@"TPMailBoxViewController" bundle:nil];
        [self presentViewController:mailBoxViewController animated:YES completion:NULL];
    }