删除故事板并使用.xib启动应用程序

时间:2013-10-22 21:51:32

标签: ios objective-c xcode xcode-storyboard

我已尝试按照此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。

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

    帮助?

4 个答案:

答案 0 :(得分:6)

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

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

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 "RootViewController.h"下面添加#import "AppDelegate.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文件一样对应用程序进行编码!祝你好运!

答案 1 :(得分:3)

1.添加viewcontroller文件所有者类

enter image description here

2.AppDelegate .h文件

@property(强,非原子)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;

答案 2 :(得分:2)

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

enter image description here

答案 3 :(得分:1)

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