2012-07-05 100 views
0

我剛剛更新了我的Xcode從4.2到4.3.3,並且我一直遇到問題 是否有可能在單個視圖應用程序中添加導航控制器,因爲當我嘗試將一個嵌入到控制器中時什麼都沒發生。我想有兩個視圖控制器通過按鈕連接到第二個控制器,導航欄連接到第一個視圖控制器。嵌入式導航控制器

我想不出任何其他方式來連接視圖控制器,請幫我 任何想法。

+0

我想你使用了.xib文件。使用.storyboard文件。 – 2012-07-05 09:33:31

回答

2
  1. 如果你不希望添加導航控制器,你可以在你現有的視圖控制器之間使用presentViewController從第一個到第二個,和dismissViewControllerAnimated去返回變換。如果你想添加一個導航控制器與你的NIB保持同步,你可以相應地改變你的應用程序委託。

所以,你可能有一個應用程序的委託,說是這樣的:

// AppDelegate.h 

#import <UIKit/UIKit.h> 

@class YourViewController; 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) YourViewController *viewController; 

@end 

更改爲添加導航控制器(你可以在這裏擺脫了先前的參考到您的主視圖控制器) :

// AppDelegate.h 

#import <UIKit/UIKit.h> 

//@class YourViewController; 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 

//@property (strong, nonatomic) YourViewController *viewController; 
@property (strong, nonatomic) UINavigationController *navigationController; 

@end 

,然後在您的應用程序委託的實現文件,你有一個didFinishLaunchingWithOptions,可能說是這樣的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

    self.viewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil]; 
    self.window.rootViewController = self.viewController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

您可以更改的說:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

    //self.viewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil]; 
    //self.window.rootViewController = self.viewController; 

    YourViewController *viewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil]; 
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 
    self.window.rootViewController = self.navigationController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

已經這樣做了,你現在可以導航到一個發鈔銀行視圖控制器到另一個人的使用pushViewControllerpopViewControllerAnimated返回。在您的viewDidLoad中,您還可以使用self.title = @"My Title";命令來控制顯示在視圖導航欄中的內容。您可能還需要改變你的發鈔銀行的「頂酒吧」屬性包括導航欄模擬指標,這樣就可以佈局你的屏幕,有什麼它會看起來像一個良好的感覺:

enter image description here

顯然,如果你有一個非ARC項目,這些視圖控制器的alloc/init行也應該有autorelease(當你看看你的應用程序委託時,這是顯而易見的)。

相關問題