2013-02-14 42 views
0

我想跟着在.xib文件中有一个appdelegate对象的苹果photopicker例子。 appdelegate对象如何进入xib文件,为什么它很重要?appdelegate在xib中的对象

在我的应用程序中,我想要一个像photopicker例子一样的导航控制器。我的测试工作没有包含导航控制器,并且我现在很难将其中一个插入到我的测试工作中,因为界面生成器似乎已经决定不允许添加。对于我来说,重新开始一个带有导航控制器体系结构的新应用程序,然后添加我的测试工作方法和类的副本,对我来说最简单吗?还是开始过度不必要?我怀疑将appdelegate对象插入xib将允许我更直接地使用现有的测试工作。

更新0

我觉得我跟着你的答案说明。 Xcode建议_viewController,我改变了这一点。我的应用程序适用于iPad和iPhone(我现在只在iPad上工作),所以我认为它有点复杂。我编译好,但我仍然没有看到我的xib文件中的appdelegate对象,即使PhotoPicker的xib文件有一个。

我怀疑我需要连接一些对象,但我也可以使用一些帮助。在PhotoPicker中,导航控制器的Connections Inspector表示参考插座位于navControllerAppDelegate之间,而AppDelegate的Connections Inspector表示参考插座位于delegateFile's Owner之间。但是因为我的xib文件没有(BS)AppDelegate对象,所以我不知道如何在没有它的情况下连接。

@interface BSAppDelegate() 
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 
@end 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPhone" bundle:nil]; 
    } else { 
     self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPad" bundle:nil]; 
    } 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController]; 
    self.window.rootViewController = navigationController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

更新0

回答

3

内(BOOL)申请:(UIApplication的*)应用程序didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions,您可以添加UINavigationController的是这样的:

UIViewController *viewController = … //load your first view controller with the initial xib here 
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 
self.window.rootViewController = navigationController; 
+0

你的答案看起来有希望。请看看我编辑的问题,因为我还没有完成。 – zerowords 2013-02-15 04:38:15

+0

哦,我不明白你的要求。我想你想在你的viewcontroller的顶部添加uinavigationcontroller。如果你想在你的xib中有AppDelegate对象,你可以看到这个答案:http://stackoverflow.com/questions/9206502/how-to-add-app-delegate-back-to-mainwindow-xib – dthien 2013-02-15 04:58:36

+0

请添加你的对这个问题发表评论,以便我可以接受它。顺便说一句,我偶然发现了你的链接响应,因为当我第一次在对象库中查找一个“对象”时,我并没有意识到有一个名为Object的对象,并试图欺骗一些其他对象成为一个对象。我的不好,但这种事情需要我很多的学习时间。谢谢。 – zerowords 2013-02-15 22:04:09