Xcode without Storyboard and ARC

雨燕双飞 提交于 2019-11-26 06:11:58

问题


i have downloaded new xcode-5 and just started using it.

We can create application directly including storyboard and ARC , it is not asking for option like earlier versions.

So, my question is how can we use xcode5 without ARC and storyboard. we have to manually remove storyboard file ? or is there any other option.


回答1:


Create a project with an Empty application and Add any viewcontroller (i added TestViewController here)

   - (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;
 }

STEPS FOR REMOVE ARC

1) In build setting set Automatic Reference Counting to NO.

///////////////////////////////////////////////////////////////////////////END///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

If you have Already Created Application with storyboard and ARC then

STEPS FOR REMOVE STORY BOARD

1) Remove Main.storyboard file from your project.

2) Add new files with xib for your controller , if it is not added in compiled sources in build phases then add there manually.

3) Remove Main storyboard file base name from plist.

4) Change appdelegate didFinishLaunchingWithOptions file and add :

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;

[self.window makeKeyAndVisible];

just like :

  - (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;
}


Now,in above example you have to manage memory management manually like ,

 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

 [test release]; 

STEPS FOR REMOVE ARC

1) In build setting set Automatic Reference Counting to NO.




回答2:


Instead of delete the storyboard file, you can Create a new project with Empty Application template. So that you can avoid the storyboard file creation.

Use following steps to omit storyboard:

  1. Create a new project with Empty Application template.
  2. Add a new viewController (Example: LoginViewController)
  3. Change the didFinishLaunchingWithOptions in AppDelegate.m file as specified below.

Change To:

#import "LoginViewController.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc]  initWithRootViewController:loginVC];

    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

Remove ARC: Go to Build Setting -> Objective-C Automatic Reference Counting -> NO




回答3:


create new project

![Create new Project]

//remove Main storyboard file base name in Info

Add This Code In appdelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc]  initWithRootViewController:loginVC];

    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

Then automatic remove your storyboard.

Please Try this... successfully Executed. thanks




回答4:


ShortCut: I Prefer

Create the project without Storyboard and ARC in xcode4 and then open that project in xcode5 .




回答5:


Xcode 4 had the "Use Storyboards" checkbox when you created a new project. It is possible to grab the old Xcode 4 application templates (XML files) and convert them to Xcode 5. That way, you get the old templates back that let you choose whether you want storyboards or not.


I wrote a script that does all that work for you: https://github.com/jfahrenkrug/Xcode4templates


After running the script, you will have an "Xcode 4" section in the "New Project" screen:

And then - Alas! - you get your beloved choices back:

You will need a copy of the Xcode 4 .app bundle from http://developer.apple.com/ios to use this script.




回答6:


I have a Tip:

  1. The First: I create my project by XCode 4.6 (Because this version is nearest to XCode 5).
    • Of course that with XCode 4.6, you can chose use or not using ARC, Storyboard.
  2. The Second: After that I will open my Project with XCode 5. => I think that Xcode 5 will understand that project is use nonARC, and of course, do not have Storyboard.

I hope your project will work! :D



来源:https://stackoverflow.com/questions/17234172/xcode-without-storyboard-and-arc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!