iOS - 在没有 xib 的项目中创建 xib

Posted

技术标签:

【中文标题】iOS - 在没有 xib 的项目中创建 xib【英文标题】:iOS - Create xib in a project without xib 【发布时间】:2012-05-29 10:15:47 【问题描述】:

this 项目有问题,它没有 xib 文件或情节提要。 该项目使用以下代码立即将 appdelegate 文件调用到 main 中:

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

在应用程序委托文件中,我们有视图控制器的声明,而不是在我的项目中,我有一个带有视图的 xib。 如果我想在现有项目中连接它怎么办?

【问题讨论】:

【参考方案1】:

1)制作自己的 xib/nib,例如 MainWindow.xib。 MainWindow.xib 中应该有三个对象,即您的“AppDelegate”、UIWindow 和 UINavigationViewController。将您的根视图控制器插入 UINavigationController。

2) 将 MainWindow 添加到 Info.plist 中,即设置“Main nib file base name”为“Main Window”

3) 将 IBOutlets 连接到您的 appdelegate。示例:

@interface AppDelegate : NSObject <UIApplicationDelegate>

    UIWindow *window;
    UINavigationController *navigationController;


@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

附:如果你使用 StoryBoards,这里有简单简洁的官方指南:Converting to Storyboards Release Notes

【讨论】:

谢谢!但我使用故事板。 我扩展了我的答案。 “转换为 Stroyboards 发行说明”似乎清晰易懂。希望对您有所帮助!

以上是关于iOS - 在没有 xib 的项目中创建 xib的主要内容,如果未能解决你的问题,请参考以下文章