如何覆蓋UINavigationController中的initWithRootViewController方法?如何覆蓋initWithRootViewController
xcode對我來說唯一的方法是在loadFromNibName和loadView等方法。這些方法不會被調用,我需要在啓動時將NSNotification添加到navigationcontroller。
我知道這看起來有點像下面的,但我不知道放什麼方法體
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
// what goes here?
}
編輯 我想真正的問題是「你怎麼自定義初始化」
編輯2
我的導航控制器頭
期間的UIViewController@interface AccountViewNavigationController : UINavigationController {
}
@end
實例化我的UINavigationController像這樣將導致沒有啓動方法打破發點
accountViewNavController = [[UINavigationController alloc] initWithRootViewController:accountView];
在哪裏,如果我實例,像這樣的loadView不會被調用....但它被調用無數次
accountViewNavController = [[UINavigationController alloc] init];
[accountViewNavController initWithRootViewController:accountView NO];
我對這個階段非常困惑。
你爲什麼要重寫它?如果你正在使用xib,你可以簡單地將RootViewController類改爲另一個UIViewController子類 – lostInTransit 2011-05-17 11:03:20
我想添加以下內容.. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveMyEvent :) name:@「MyEvent」object :零]; – dubbeat 2011-05-17 11:05:00