[英]Tab bar Items not showing properly
Figure 1 displays a dynamically created tab bar controller that was loaded when the application starts: 图1显示了动态创建的选项卡栏控制器,该控件在应用程序启动时加载:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
autoMagically = [[AutoMagically alloc] initWithNibName:nil bundle:nil];
[self.window addSubview:autoMagically.view];
[self.window makeKeyAndVisible];
return YES;
}
if i load it by clicking a button on a view (the way i want and need to do it) i get whats shown in figure 2 of the picture above: 如果我通过单击视图上的按钮来加载它(我想要和需要的方式),我将得到上图的图2所示的内容:
-(void) loadWhenClicked{
AutoMagically *todaysDeal = [[AutoMagically alloc] initWithNibName:nil bundle:nil];
todaysDeal.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:todaysDeal animated:YES];
[todaysDeal release];
}
Heres my code for creating the tab bar: 这是我用于创建标签栏的代码:
tabBarController = [[UITabBarController alloc] init];
FirstViewController* vc1 = [[FirstViewController alloc] init];
SecondViewController* vc2 = [[SecondViewController alloc] init];
vc1.title = @"Dallas";//[[NSUserDefaults standardUserDefaults] objectForKey:@"Citynamefrmhome"];
vc1.tabBarItem.image = [UIImage imageNamed:@"Dealss.png"];
vc2.title = @"My Vouchers";
vc2.tabBarItem.image = [UIImage imageNamed:@"nav_voucher_S.png"];
NSArray* controllers = [NSArray arrayWithObjects:vc1,vc2, nil];
tabBarController.viewControllers = controllers;
[self.view addSubview:tabBarController.view];
How do i make the tab bar controller show properly like in figure 1 when i load it like i would any other view? 加载时如何像其他视图一样正确显示标签栏控制器,如图1所示? This is an iphone view based app using xcode 4.
这是使用xcode 4的基于iPhone视图的应用程序。
So the problem is UITabController is a view controller so it's not really something you want add to the display with addSubview (since it's not a view). 因此,问题在于UITabController是一个视图控制器,因此它不是您真正想要通过addSubview添加到显示中的东西(因为它不是视图)。 Instead, mod your code to do this and you'll be fine:
相反,修改您的代码来做到这一点,您会没事的:
UITabBarController *todaysDeal = [[UITabBarController alloc] init];
FirstViewController* vc1 = [[FirstViewController alloc] init];
SecondViewController* vc2 = [[SecondViewController alloc] init];
vc1.title = @"Dallas";//[[NSUserDefaults standardUserDefaults] objectForKey:@"Citynamefrmhome"];
vc1.tabBarItem.image = [UIImage imageNamed:@"Dealss.png"];
vc2.title = @"My Vouchers";
vc2.tabBarItem.image = [UIImage imageNamed:@"nav_voucher_S.png"];
NSArray* controllers = [NSArray arrayWithObjects:vc1,vc2, nil];
todaysDeal.viewControllers = controllers;
todaysDeal.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:todaysDeal animated:YES];
[todaysDeal release];
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.