2011-12-02 48 views
0

我創建了一個非常簡單的應用程序,並以UINavigationController作爲根控制器,但是當我運行它時,只顯示導航欄的一半(左側)。爲什麼是這樣?這看起來很奇怪 - 如果我做了錯誤的事情,你會認爲它根本不會顯示,而是恰好一半!只有一半導航欄正在顯示UINavigationController

控制器看起來像這樣:

@interface RootController : UINavigationController { 
    UIWebView* webView; 
    NSMutableString  *htmlString; 
} 

與對應@property聲明和@synthesize。

我沒有使用任何.nibs視圖控制器/視圖。該應用程序的委託是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    RootController* theRVC = [[RootController alloc] init]; 
    self.window.rootViewController = theRVC; 
    [theRVC release]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

而且控制器具有以下相關代碼:

- (void)loadView 
{ 
    webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    self.view = webView; 
    [webView release]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

回答

1

你不應該從UINavigationController派生。

取而代之,從UIViewController派生你的RootController類。 然後,在應用程序委託中,初始化一個傳入RootController的UINavigationController,並將其設置爲Windows rootViewController。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    RootController* theRVC = [[RootController alloc] init]; 
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:theRVC]; 
    self.window.rootViewController = navController; 
    [theRVC release]; 
    [navController release]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
+0

謝謝。從UINavigationController派生出來總是不正確的嗎? – Gruntcakes

+0

很少需要從UINavigationController派生。如果你願意,這將是定製導航控制器本身的某個方面,而不是定義內容視圖控制器。 –