Remove storyboard and start app with a .xib
Asked Answered
S

4

6

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.

Here are the steps:

  1. Copied all items on the view in the story board and pasted into the new xib view.
  2. Copied all contents of .h and .m view controller files into the new ones for the xib.
  3. Changed the Main nib file base name to the new xib name in the info.plist file.
  4. Tried to change the owner but I don't know if I'm doing that correctly.
  5. 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;
    }
    
  6. 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.

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.

Help?

Symptomatology answered 22/10, 2013 at 21:51 Comment(4)
Repeat of this question here... #17234672Eurasian
Try this link.... this should get you what you are trying to do... #17234672Eurasian
I put the above links in as an answer :(Eurasian
@Eurasian - this is the same link I posted. Great information. BTW: I tried it again and the second time it worked!!! :-)Symptomatology
A
6

You're going to want to create an empty application, then press cmd + n and choose coca touch > objective-c class. name the class RootViewController and leave the subclass alone (UIViewController) then check 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

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:

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

So your entire AppDelegate.h should now 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've done all of this you should be able to start coding your application like you usually would for a xib file! Good luck!

Ambitious answered 23/10, 2013 at 4:17 Comment(0)
N
3

1.Add viewcontroller Files Owner class

enter image description here

2.AppDelegate .h File

@property (strong, nonatomic) 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;
Noyes answered 7/9, 2015 at 8:43 Comment(0)
K
2

Did you assign appropriate class in identity inspector of xib file?

enter image description here

Kedah answered 22/10, 2013 at 21:54 Comment(1)
Great thing to check. But starting with an empty project worked for me when I tried it for the second time. Xcode must have gone wonky on me. Thanks for your help.Symptomatology
H
2

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 :)

Hattie answered 7/2, 2015 at 23:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.