2012-05-28 36 views
0

我有一個代碼爲UItabviewcontroller使用編程方式,但如何創建其框架,因爲我在我的應用程序中使用我需要x,y寬度和高度座標的子視圖。我們可以使用UITabBarController * tabBarController = [[UITabBarController alloc] init];如何創建與框架UITabviewcontroller

UIViewController *vc1 = [[UIViewController alloc] init]; 
UIViewController *vc2 = [[UIViewController alloc] init]; 

UIView *v1 = [[UIView alloc] init]; 
UIView *v2 = [[UIView alloc] init]; 

vc1.title = @"vc1"; 
vc2.title = @"vc2"; 

tabBarController.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil]; 

self.view = tabBarController.view; 

回答

0

當你用ios5標記你的問題時,我想你的應用程序只運行在ios5上。如果我理解你是對的,你想在另一個視圖控制器視圖中顯示tabBarController。

在5.0之前,這是不可能的,沒有一些非常醜陋的黑客。但是對於iOS5.x,現在有一個API。查看'Implementing a Container View Controller'中的UIViewController文檔。您必須將tabBarController設置爲當前視圖控制器的子視圖控制器。您可以指定您想要的框架,並將其添加到您的視圖中。