xcode 删除故事板并使用 .xib 启动应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19529086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove storyboard and start app with a .xib
提问by Patricia
I've tried to follow the instructions on this Question. But I must not be doing something correctly because I am still getting a SIGABRT before I even get into the ViewController methods.
我已尝试按照有关此问题的说明进行操作。但是我一定没有做正确的事情,因为我什至在进入 ViewController 方法之前仍然收到了 SIGABRT。
Here are the steps:
以下是步骤:
- Copied all items on the view in the story board and pasted into the new xib view.
- Copied all contents of .h and .m view controller files into the new ones for the xib.
- Changed the Main nib file base name to the new xib name in the info.plist file.
- Tried to change the owner but I don't know if I'm doing that correctly.
Edited the appdelegate didFinishLaunchingWithOptions file as follows:
- (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; }
I even tried to start with an empty project like one of the last posts suggested and still get a SIGABRT when I try to run.
- 复制故事板视图中的所有项目并粘贴到新的 xib 视图中。
- 将 .h 和 .m 视图控制器文件的所有内容复制到 xib 的新文件中。
- 在 info.plist 文件中将 Main nib 文件基本名称更改为新的 xib 名称。
- 试图改变所有者,但我不知道我这样做是否正确。
编辑 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。
Has Apple made it impossible to remove the storyboard? I'm creating an SDK. I don't want a storyboard. But I do need one xib that is rotatable.
Apple 是否已经无法移除故事板?我正在创建一个 SDK。我不想要故事板。但我确实需要一个可旋转的 xib。
Help?
帮助?
采纳答案by Jojodmo
You're going to want to create an empty application, then press cmd+ nand choose coca touch > objective-c class
. name the class RootViewController and leave the subclass alone (UIViewController
) then check With XIB for user interface
.
您将要创建一个空的应用程序,然后按cmd+n并选择coca touch > objective-c class
。将类命名为 RootViewController 并保留子类 ( UIViewController
) 然后检查With XIB for user interface
.
Once you've done that, go into your AppDelegate.m file and add the following code under - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
above return: YES
完成后,进入您的 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];
So, it should now look like this:
所以,它现在应该是这样的:
- (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;
}
then, add #import "RootViewController.h"
just below #import "AppDelegate.h"
. after you do that, go to your AppDelegate.h file, and add @class RootViewController;
above the @interface. Then, add the following code under @interface AppDelegate
:
然后,#import "RootViewController.h"
在下面添加#import "AppDelegate.h"
。完成后,转到您的 AppDelegate.h 文件,并@class RootViewController;
在 @interface 上方添加。然后,在下面添加以下代码@interface AppDelegate
:
@property (strong, nonatomic) RootViewController *RootViewController;
@property (strong, nonatomic) UINavigationController *navController;
So your entire AppDelegate.h
should now look like this:
所以你的整体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
Now that you've done all of this you should be able to start coding your application like you usually would for a xib file! Good luck!
现在您已经完成了所有这些工作,您应该能够像平常编写 xib 文件一样开始编写您的应用程序了!祝你好运!
回答by Gami Nilesh
1.Add viewcontroller Files Owner class
1.添加viewcontroller Files Owner类
2.AppDelegate .h File
2.AppDelegate.h文件
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) ViewController *viewController;
3.AppDelegate .m File
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;
}
or
或者
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;
回答by Nandan Sawant
Look inside your info.plist. Does it still contain the key UIMainStoryboardFile ("Main storyboard file base name") with value "Main"? Remove this key value pair and that should fix your problem :)
查看您的 info.plist。它是否仍然包含值为“Main”的键 UIMainStoryboardFile(“Main storyboard file base name”)?删除此键值对,这应该可以解决您的问题:)
回答by Obj-Swift
Did you assign appropriate class in identity inspector of xib file?
您是否在 xib 文件的身份检查器中分配了适当的类?