2013-11-25 93 views
0

我正在通過BNR名爲「IOS編程」的書學習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 
+0

選中故事板,我在這所以很新的這可能是一個非常愚蠢的問題,但對於那些回答這個問題的人,請提前致謝! – Tosh

+0

看起來你想導入頭文件TestViewController.h。您可以添加顯示此警告的代碼 –

+0

謝謝Anil!當我添加頭文件TestViewController.h時,一切看起來都很好! – Tosh

回答

0

從模板創建一個空的應用程序。而再添加一個視圖控制器通過向右擊項目,並添加新的文件,然後選擇並選擇在左窗格中可可觸摸。

然後選擇第一個選項Objective-C Class,然後爲該類命名。

enter image description here

從subclasss選擇的UIViewController。

enter image description here

請與選項確保複選框「隨着廈門國際銀行或用戶界面」被選中,然後單擊下一步。

沒有情節串連圖板項目中的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; 
} 
+0

謝謝,但如果我不僅添加一個ViewController而是一個NavigationController?我應該在「 - (BOOL)應用程序:(UIApplication *)應用程序didFinishLaunchingWithOptions:」中放入AppDelegate.m文件中的內容嗎? – Tosh

+0

是的,我會編輯你的問題的答案 – Vinodh

+0

我編輯了我的答案你可以看看上面的代碼 – Vinodh

0

項目創建時選中故事板選項

新項目 - >單一視圖 - >像下面的圖像 enter image description here

+0

@I_Like_IOS,謝謝,但不幸的是我使用Xcode 5。 – Tosh

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; 
    } 
+0

哇!作品!謝謝:)) – Tosh