【问题标题】:Remove storyboard and start app with a .xib删除故事板并使用 .xib 启动应用程序
【发布时间】:2013-10-31 23:39:06
【问题描述】:

我已尝试按照Question 上的说明进行操作。但我一定没有正确地做某事,因为在我进入 ViewController 方法之前我仍然得到一个 SIGABRT。

步骤如下:

  1. 复制故事板中视图上的所有项目并粘贴到新的 xib 视图中。
  2. 将 .h 和 .m 视图控制器文件的所有内容复制到 xib 的新文件中。
  3. 将主 nib 文件基名称更改为 info.plist 文件中的新 xib 名称。
  4. 试图更改所有者,但我不知道我这样做是否正确。
  5. 将 appdelegate didFinishLaunchingWithOptions 文件编辑如下:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    
     {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
    
         // Override point for customization after application launch.
    
         TestViewController *test = [[TestViewController alloc]         initWithNibName:@"TestViewController" bundle:nil];
         UINavigationController *nav = [[UINavigationController alloc]  initWithRootViewController:test];
         self.window.rootViewController = nav;
    
         [self.window makeKeyAndVisible];
    
         return YES;
    }
    
  6. 我什至尝试从一个空项目开始,就像最后一篇文章建议的那样,当我尝试运行时仍然得到一个 SIGABRT。

Apple 是否已让故事板无法移除?我正在创建一个 SDK。我不想要故事板。但我确实需要一个可旋转的 xib。

帮助?

【问题讨论】:

标签: ios objective-c xcode xcode-storyboard


【解决方案1】:

您将要创建一个空应用程序,然后按 cmd + n 并选择 coca touch > objective-c class。将类命名为 RootViewController 并保留子类 (UIViewController),然后检查 With XIB for user interface

完成此操作后,进入 AppDelegate.m 文件并在上面的 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 下添加以下代码返回:YES

self.RootViewController = [[RootViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.RootViewController];
self.navController.navigationBarHidden = YES;
[self.window addSubview:self.navController.view];

所以,它现在应该是这样的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    self.RootViewController = [[RootViewController alloc] init];
    self.navController = [[UINavigationController alloc] initWithRootViewController:self.RootViewController];
    self.navController.navigationBarHidden = YES;
    [self.window addSubview:self.navController.view];
    return YES;
}

然后,在#import "AppDelegate.h" 下方添加#import "RootViewController.h"。完成此操作后,转到您的 AppDelegate.h 文件,然后在 @interface 上方添加 @class RootViewController;。然后,在@interface AppDelegate下添加如下代码:

@property (strong, nonatomic) RootViewController *RootViewController;
@property (strong, nonatomic) UINavigationController *navController;

所以你的整个AppDelegate.h 现在应该是这样的:

#import <UIKit/UIKit.h>

@class RootViewController;

     @interface AppDelegate : UIResponder <UIApplicationDelegate>


     @property (strong, nonatomic) UIWindow *window;
     @property (strong, nonatomic) RootViewController *RootViewController;
     @property (strong, nonatomic) UINavigationController *navController;

@end

现在您已经完成了所有这些,您应该可以开始编写应用程序,就像通​​常编写 xib 文件一样!祝你好运!

【讨论】:

    【解决方案2】:

    1.添加viewcontroller Files Owner类

    2.AppDelegate .h 文件

    @property (strong, nonatomic) ViewController *viewController;

    3.AppDelegate .m 文件

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    ViewController *loginVC = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc]  initWithRootViewController:loginVC];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    
    return YES;
    

    【讨论】:

      【解决方案3】:

      您是否在 xib 文件的身份检查器中分配了适当的类?

      【讨论】:

      • 检查的好东西。但是当我第二次尝试时,从一个空项目开始对我有用。 Xcode 一定对我很奇怪。感谢您的帮助。
      【解决方案4】:

      查看您的 info.plist。它是否仍然包含值为“Main”的键 UIMainStoryboardFile(“主故事板文件基本名称”)?删除这个键值对应该可以解决你的问题:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-04
        • 1970-01-01
        相关资源
        最近更新 更多