添加导航栏到Tap吧

时间:2014-01-02 10:24:13

标签: ios objective-c

我想要一个公共导航栏到RecieptViewController和StockViewController,并且栏应该包含后退按钮以返回到InventoryViewController ..... 此代码是在InventoryViewController viewDidLoad中编写的: -

RecieptViewController *firstVC=[[RecieptViewController alloc]init];
UITabBarItem *itme1=[[UITabBarItem alloc]initWithTitle:@"First" image:nil tag:1];
itme1.title=@"Reciept";
[firstVC setTabBarItem:itme1];

StockViewController *secondView=[[StockViewController alloc]init];
UITabBarItem *item2=[[UITabBarItem alloc]initWithTitle:@"Second" image:nil tag:2];
item2.title=@"Stock";
[secondView setTabBarItem:item2];

[tapBarController setViewControllers:[NSArray arrayWithObjects:firstVC,secondView,nil]];

1 个答案:

答案 0 :(得分:0)

如果要向UITabBarController添加导航控制器,则必须尝试以下操作:

UIViewController *viewController1, *viewController2;
UINavigationController *navigationController1, *navigationController2;

viewController1 = [[RecieptViewController alloc] initWithNibName:@"RecieptViewController" bundle:nil];
viewController2 = [[StockViewController alloc] initWithNibName:@"StockViewController" bundle:nil];

navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];

[tapBarController setViewControllers:[NSArray navigationController1,navigationController2,nil]];