0

我正在尝试遵循 apple photopicker 示例,该示例在 .xib 文件中有一个 appdelegate 对象。appdelegate 对象如何进入 xib 文件,为什么它很重要?

在我的应用程序中,我想要一个像 photopicker 示例那样的导航控制器。我的测试工作没有包含导航控制器,我很难将导航控制器插入到我的测试工作中,因为它只有一个视图控制器,因为界面构建器似乎已经决定不允许添加。对我来说,最简单的方法是从一个具有导航控制器架构的新应用程序开始,然后添加我的测试工作方法和类的副本。还是没有必要重新开始?我怀疑将 appdelegate 对象插入 xib 将允许我更直接地使用现有测试工作。

更新 0

我想我按照您的回答中的说明进行了操作。Xcode 建议_viewController,我改变了它。我的应用程序适用于 iPad 和 iPhone(我现在只在 iPad 上工作),所以我认为它有点复杂。我编译得很好,但我的 xib 文件中仍然没有 appdelegate 对象,即使 PhotoPicker 的 xib 文件有一个。

我怀疑我仍然需要连接一些对象,但我也可以使用一些帮助。在 PhotoPicker 中,Navigation Controller 的 Connections Inspector 表示引用 Outlet 在navControllerand之间AppDelegate,而 AppDelegate 的 Connections Inspector 表示 Reference Outlet 在delegateand之间File'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

4

1 回答 1

3

在 (BOOL)application:(UIApplication *)application 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;
于 2013-02-14T23:24:16.650 回答