Delete the storyboard and run the application using .xib

I tried to follow the instructions on this Question . But I should not do something right, because I still get SIGABRT before I even get into the ViewController methods.

Here are the steps:

  • I copied all the elements in the view in the story pane and pasted them into the new xib view.
  • Copied all the contents of the .h and .m control files to the new ones for xib.
  • The base name of the main nib file for the new xib name in the info.plist file has been changed.
  • Trying to change the owner, but I do not know if I am doing this 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, as one of the last posts posted, and still get SIGABRT when I try to start.

Could Apple delete the storyboard? I am creating an SDK. I do not want a storyboard. But I need one xib that can rotate.

reference

+6
source share
4 answers

You need to create an empty application, then press cmd + n and select coca touch > objective-c class . name the class RootViewController and leave the subclass one ( UIViewController ), then check With XIB for user interface .

Once you do this, go to the AppDelegate.m file and add the following code to - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions above: YES

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

So now it should 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 that go to the file AppDelegate.h and add @class RootViewController; over @interface. Then add the following code under @interface AppDelegate :

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

So, your whole AppDelegate.h should look like this:

 #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 have done all this, you can start coding your application, as usual, for the xib file! Good luck

+6
source

1.Add viewcontroller Files Owner Class

enter image description here

2.AppDelegate.h File

@property (strong, non-nuclear) ViewController * viewController;

3.AppDelegate.m File

 - (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; 
+3
source

Have you assigned the appropriate class in the xib file identifier inspector?

enter image description here

+2
source

View your info.plist. Does it still contain the key UIMainStoryboardFile ("Main name of the storyboard file") with the value "Main"? Remove this key value pair and this should fix your problem :)

+1
source

Source: https://habr.com/ru/post/956511/


All Articles