2012-07-05 103 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(当你看看你的应用程序委托时,这是显而易见的)。

相关问题