创建没有故事板的项目

时间:2013-11-25 03:29:06

标签: ios iphone ios7 storyboard xcode5

我正在通过BNR的名为“IOS PROGRAMMING”的书来学习ios编程。

我需要创建一个没有故事板的项目来跟随这本书。

我只是检查下面这个答案,但它不适合我。 Xcode 5 without Storyboard and ARC

编译器在 AppDelegate.m中说“用UIViewController替换TestViewController”

#import "AppDelegate.h"


@implementation AppDelegate


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

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

3 个答案:

答案 0 :(得分:0)

从模板创建一个Empty应用程序。然后通过右键单击并添加新文件然后选择并在左窗格中选择cocoa touch,将ViewController添加到Project。

然后选择第一个选项Objective-C Class,然后为该类命名。

enter image description here

从子类中选择UIViewController。

enter image description here

确保选中“使用XIB或用户界面”选项的复选框,然后单击“下一步”。

在XCode 5中创建没有故事板的项目

如果您想要导航控制器,可以像下面的代码一样实现

<强> Appdelegate.h

#import <UIKit/UIKit.h>

@class InitialViewController;


@interface SampleAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) InitialViewController *viewController;

@end

<强> Appdelegate.m

#import "SampleAppDelegate.h"
#import "InitialViewController.h"

@implementation SampleAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[InitialViewController alloc]initWithNibName:@"InitialViewController" bundle:nil];
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:self.viewController];
    self.window.rootViewController = navi;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

答案 1 :(得分:0)

项目创建时间取消选中故事板选项

新项目 - &gt;单一视图 - &gt;未经检查的故事板如下图所示 enter image description here

答案 2 :(得分:0)

内部appdelegate

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
        self.TestViewController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
        self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.TestViewController];
        self.window.rootViewController = self.navigationController;
    }
相关问题