我已尝试按照此Question的说明操作。但我不能正确地做某事,因为在我进入ViewController方法之前我仍然得到一个SIGABRT。
以下是步骤:
编辑了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;
}
我甚至尝试从一个空项目开始,就像我建议的最后一个帖子一样,当我尝试运行时仍然会得到一个SIGABRT。
Apple是否无法删除故事板?我正在创建一个SDK。我不想要故事板。但我确实需要一个可旋转的xib。
帮助?
答案 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文件所有者类
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文件的身份检查器中分配了适当的类?
答案 3 :(得分:1)
查看您的info.plist。它是否仍包含值为“Main”的密钥UIMainStoryboardFile(“主故事板文件基本名称”)?删除此键值对,这应该可以解决您的问题:)