2012-04-02 43 views
2

我正在學習Xcode,併爲IOS開發人員擔任實習生。我正在使用Xcode 4.2和Lion OS。我的目標操作系統將是ios 3+版本。有人告訴我,使用故事板會給舊版本帶來問題。所以我想開發不使用導航控制器的Storyboard。幫助我,導致所有舊的教程根本沒有幫助,導致有很多由於xcode版本的變化造成的錯失。 請幫助我。如何在不使用storyboard和tableView的情況下在Xcode 4.2中開發NavigationController?

回答

0

當你創建新的項目

有使用故事板對號只是將其刪除從there.then前進因爲你是移動之前。 enter image description here

+0

哈哈,那不是我的問題@Neel ...但感謝...我的問題是,所有的教程都是基於舊版本的Xcode,我不能夠遵循它,比如有在xib文件中不是應用程序委託,在創建新項目期間沒有基於窗口的應用程序,因爲基於窗口的應用程序具有應用程序delegate.h和.m文件,包括mainwindow.xib ....以及許多其他事情.....請問您能否只是告訴我如何使兩個頁面的應用程序有導航,但不使用表...只是簡單的兩頁....感謝 – Pawriwes 2012-04-02 10:43:14

+0

然後有簡單的一線解決方案此返回添加在您的主要filr下面的行,並按照答案無敵。 UIApplicationMain(argc,argv,nil,NSStringFromClass([AppDelegate class])); – 2012-04-02 12:25:56

+0

如果您需要更多幫助,請在這裏詢問 – 2012-04-02 12:28:25

3

要創建導航控制器,請爲您的項目模板選擇單一視圖應用程序。在AppDelegate.h中,創建一個UINavigationController的實例。在AppDelegate.m文件,這樣做:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 
    navigationController = [[UINavigationController alloc] initWithRootViewController:(UIViewController*)viewController]; 
    [window addSubview:navigationController.view]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

這將給基地爲導航控制器。您可以在此添加其他視圖

[self.navigationController pushViewController:newViewController animated:YES]; 
+0

謝謝你的回答幫助我了很多.. – 2012-12-26 12:40:33

0

將此添加到您的AppDelegate,並與他們玩耍。看看會發生什麼,你會學到什麼。

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>{ 


} 

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) UITabBarController *tabBarController; 

@end 
//*****************************************// 

.m file 

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    UIViewController *viewController1 = [[Categories alloc] initWithNibName:@"Categories" bundle:nil]; 
    UIViewController *viewController2 = [[Coupons alloc] initWithNibName:@"Coupons" bundle:nil]; 
    UIViewController *viewController3 = [[Favourites alloc] initWithNibName:@"Favourites" bundle:nil]; 
    UIViewController *viewController4 = [[AroundMe alloc] initWithNibName:@"AroundMe" bundle:nil]; 

    viewController2.title = NSLocalizedString(@"Coupons", @"Coupons"); 
    viewController2.tabBarItem.image = [UIImage imageNamed:@"coupons.png"]; 
    viewController3.title = NSLocalizedString(@"Favourites", @"Favourites"); 
    viewController3.tabBarItem.image = [UIImage imageNamed:@"favourites.png"]; 


    // UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1]; 
    UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1]; 
    UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2]; 
    UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3]; 
    UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:viewController4]; 
    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1,navController2, navController3, navController4, nil]; 
    self.window.rootViewController = self.tabBarController; 
相關問題