No .navigationController or .tabBarController will be available for the UIView or UIViewController that were created but not pushed onto the stack
Either create a property in the View (or ViewController) class, which is a UIViewController, which is optionally provided after initialization, or you can add a third argument to initWithNibName:bundle:
@interface CustomViewController : UIViewController
{
UIViewController *owner;
}
@property (nonatomic, assign) UIViewController* owner;
@end
Then the owner of the ViewController:
CustomViewController *cvc = [[CustomViewController alloc] initWithNibNamed:nil bundle:nil];
cvc.owner = self;
Too bad .parentViewController is read-only, this would be a reasonable place for this.
source
share