2014-02-06 44 views
0

我是一名初學者的ios程序員,並構建了一個不使用故事板的應用程序。有不同的意見不同的筆尖。它也有一個委託文件。將個人視圖變爲標籤的最佳方式

如果我想從一個視圖切換到另一個視圖控制器內使用此代碼。

self.detailController = [[[DetailController alloc] 
         initWithNibName:@"DetailController" bundle:nil] autorelease]; 
self.detailController.originalObj = nil; 

SUP101AppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 
[delegate.navController pushViewController:self.detailController animated:YES]; 

也應用具有下面的代碼在代表顯示的初始視圖

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

    self.viewController = [[[SubscribeController alloc] initWithNibName:@"SubscribeController" bundle:nil] autorelease]; 
    self.navController = [[[UINavigationController alloc] initWithRootViewController: self.viewController] autorelease]; 
    self.window.rootViewController = self.navController; 
    [self.window makeKeyAndVisible]; 
    return YES; 

} 

我想改變該應用使得每個視圖在一個標籤中顯示,並從一個視圖具有結構轉換到其他應該在選項卡中發生。我嘗試了其他帖子的幾個例子,但我無法得到一個逐步的解決方案,我如何實現這個現有的應用程序基於標籤的視圖。我不知道應該添加一個選項卡控制器在xcode中使用新文件或以編程方式在視圖控制器中製作選項卡。或者我應該從基於選項卡的新項目開始,並將我的舊項目文件複製到它...請建議。

+0

在這個答案的鏈接項目,似乎做好解釋它:http://stackoverflow.com/q/3011262/ 155513。你不需要創建一個新的應用程序,只需添加一個'UITabBarController',將viewcontrollers綁定到該選項卡並實現委託方法。 – Shizam

回答

1

這裏是你修改後的代碼,對於具有4個標籤開始的TabBar控制器

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 568)]; 

UIViewController *VC1=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name 
[email protected]"VC1"; 
UINavigationController *NC1=[[UINavigationController alloc] initWithRootViewController:VC1];//set root of navigation controller 
UIViewController *VC2=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name 
[email protected]"VC2"; 
UINavigationController *NC2=[[UINavigationController alloc] initWithRootViewController:VC2];//set root of navigation controller 
UIViewController *VC3=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name 
[email protected]"VC3"; 
UINavigationController *NC3=[[UINavigationController alloc] initWithRootViewController:VC3];//set root of navigation controller 
UIViewController *VC4=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name 
[email protected]"VC4"; 
UINavigationController *NC4=[[UINavigationController alloc] initWithRootViewController:VC4];//set root of navigation controller 

UITabBarController *tabBarController=[[UITabBarController alloc] init]; 
[tabBarController setViewControllers:@[NC1,NC2,NC3,NC4]]; 

[self.window setRootViewController:tabBarController]; 

[self.window makeKeyAndVisible]; 
return YES; 
} 
相關問題