如何重寫UINavigationController的構造函數以傳入rootViewController?Monotouch:UINavigationController,覆蓋initWithRootViewController
我會像在Objective-C以下的方法:
-(id)initWithRootViewController:(UIViewController*)rootViewController
{
UIViewController *fakeController = [[[UIViewController alloc] init] autorelease];
if (self = [super initWithRootViewController:fakeController]) {
self.fakeRootViewController = fakeController;
rootViewController.navigationItem.hidesBackButton = YES;
[self pushViewController:rootViewController animated:NO];
}
return self;
}
預先感謝您。問候。
P.S的這段代碼已採取從Change the root view controller
編輯:
謝謝您的答覆。我對前面的代碼片斷感興趣,因爲它特別有趣。
@Geoff諾頓:也許我會永遠不可能用你的解決方案,但我覺得很神奇呢?
我的嘗試是創造一種UINavigationViewController,它充當一個模板。尤其是,UINavigationController最初有一個loginView(它可能是一種rootviewcontroller)。然後登錄時,我可以有兩種類型的視圖:主視圖和次視圖。前者與登錄視圖處於同一級別(它們可能是一種rootview控制器)。後者被推到第一個以上。您可以瀏覽普通的UInavigationController堆棧或工具欄。工具欄只加載主視圖。
是否可以用UINavigationController來做到這一點?
再次感謝您。問候。