gpt4 book ai didi

iphone - 如何将 UITabBarController 设置为查看?

转载 作者:行者123 更新时间:2023-12-01 19:21:52 25 4
gpt4 key购买 nike

我有一个有多个 View 的应用程序。在一个 View 中,我想添加一个 UITabBarController .

在另一个应用程序中,我使用它来添加 UITabBarControllerrootViewController ,但我不确定这是否是正确的方法。

在.h

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

在他们中
@synthesize tabBarController=_tabBarController;
self.window.rootViewController = self.tabBarController;

最佳答案

在我的一个应用程序中,我使用此代码在应用程序之间设置 tabbarcontroller

在 AppDelegate.m 中定义标签栏 Controller

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate=self;
self.tabBarController.selectedIndex=0;
self.tabBarController.delegate=self;


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
//NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewController];

// return YES;
}

在您想要使用标签栏 Controller 推送 Controller 的位置应用以下代码
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *viewController1 = [[GeneralViewController alloc] initWithNibName:@"GeneralViewController" bundle:nil];
UIViewController *viewController2 = [[MiscQuotationController alloc] initWithNibName:@"MiscQuotationController" bundle:nil];
UIViewController *viewController4 = [[QuotationListController alloc] initWithNibName:@"QuotationListController" bundle:nil];
UIViewController *viewController5 = [[ChargesViewController alloc] initWithNibName:@"ChargesViewController" bundle:nil];
UIViewController *viewController7 = [[SalesPartViewController alloc] initWithNibName:@"SalesPartViewController" bundle:nil];

/// tab button title
viewController1.title = @"Basic information";
viewController2.title = @"Misc Quotation";
viewController4.title = @"Quotation Line";
viewController5.title = @"Charges";
viewController7.title = @"Sales Part Stock";

// tab button Images
viewController1.tabBarItem.image = [UIImage imageNamed:@"general.png"];
viewController2.tabBarItem.image = [UIImage imageNamed:@"misle.png"];
viewController4.tabBarItem.image = [UIImage imageNamed:@"history.png"];
viewController5.tabBarItem.image = [UIImage imageNamed:@"charges.png"];
viewController7.tabBarItem.image = [UIImage imageNamed:@"shoebox.png"];

delegate.tabBarController = [[UITabBarController alloc] init];
delegate.tabBarController.selectedIndex = 0;
delegate.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController4, viewController5, viewController7, nil];
delegate.tabBarController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController pushViewController:delegate.tabBarController animated:YES];

关于iphone - 如何将 UITabBarController 设置为查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9976839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com