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

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

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

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

【问题讨论】:

    标签: objective-c ios xcode delegates 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 发行说明”似乎清晰易懂。希望对您有所帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 2015-07-24
    • 2011-01-14
    • 1970-01-01
    • 2012-09-26
    相关资源
    最近更新 更多