开发者

how to overwrite initWithRootViewController

开发者 https://www.devze.com 2023-03-06 22:42 出处:网络
How can I overwrite the initWithRootViewControllermethod in a UINavigationController? The only methods generated by xcode for me where methods suchs as loadFromNibName and loadView. These methods do

How can I overwrite the initWithRootViewController method in a UINavigationController?

The only methods generated by xcode for me where methods suchs as loadFromNibName and loadView. These methods don't get called and I need to add an NSNotification to the navigationcontroller at startup.

I know it looks a little like the following but I don't know what put in the body of the method

- (id)initWithRootViewController:(UIViewController *)rootViewController

{
 // what goes here?
}

EDIT I guess the question really is "how do you customize a UIViewCOntroller during initialization"

Edit 2

My Navigation Controller header

@interface AccountViewNavigationController : UINavigationController {

}
@end

Instantiating my UINavigationController Like so will result in no startup methods hitting break point

accountViewNavController = [[UINavigationController alloc] initWithRootViewController:accountView];

Where as if I instantiate like so loadView does get called.... but it gets called numerous times

accountViewNavController = [[UINavigationController alloc] init];

[accountViewNavContro开发者_如何学编程ller initWithRootViewController:accountView NO];

I'm highly confused by this stage.


Use the same basic structure you use for overriding any other init method:

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
    if ((self = [super initWithRootViewController:rootViewController])) {
        // Your modifications go here
    }
    return self;
}

Do note that Apple claims UINavigationController is "not intended for subclassing", but they don't absolutely forbid it. I guess that means "don't try to change how the class works by messing with the internal message flow".

0

精彩评论

暂无评论...
验证码 换一张
取 消