6

我已尝试按照有关此问题的说明进行操作。但我不能正确地做某事,因为在我进入 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。

帮助?

4

4 回答 4

6

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

完成后,进入 AppDelegate.m 文件并在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions上面的 return 下添加以下代码: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 "RootViewController.h"在下面添加#import "AppDelegate.h"。完成此操作后,转到您的 AppDelegate.h 文件,然后@class RootViewController;在 @interface 上方添加。然后,在下面添加以下代码@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 文件一样!祝你好运!

于 2013-10-23T04:17:53.770 回答
3

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;
于 2015-09-07T08:43:47.633 回答
2

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

在此处输入图像描述

于 2013-10-22T21:54:05.450 回答
2

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

于 2015-02-07T23:46:38.993 回答