gpt4 book ai didi

objective-c - 点击选项卡栏项目 View 在 iphone 中没有改变

转载 作者:行者123 更新时间:2023-11-29 13:41:31 25 4
gpt4 key购买 nike

我想在我的基于 View 的应用程序的 View 之一中使用选项卡栏。所以我拖了一个标签栏并添加了 2 个标签栏项目,使它总共有 4 个。

我已经分别用 Myservices、History、RecentRequest 和 profile 标签用 1、2、3、4 标记了每个选项卡项。

类似地,我为每个选项卡添加了 4 个类,名称为 Myservices.h、.m、.xib 名称,其他选项卡的名称也与上面相同。

在上面的选项卡 3 是 UITableViewController 的子类,配置文件选项卡是 UIVIewController 的子类。当我单击配置文件选项卡时,它显示 tableView,我也在其他 View 中做了一些修改,但是单击任何选项卡时,它显示所有选项卡的相同屏幕,所以任何人都可以告诉我哪里出错了。

这是我的代码,我在名为 Homepage.h 和 .m 的类中添加了这段代码,并且将标签栏拖到 homepage.xib 中

//代码主页.h

IBOutlet UITabBar *myTabBar; 
UIViewController *myServicesViewController;
UIViewController *historyViewController;
UIViewController *recentRequestViewController;
UIViewController *profileViewController;
UIViewController *currentViewController;

@property (nonatomic, retain) IBOutlet UITabBar *myTabBar;
@property (nonatomic, retain) UIViewController *myServicesViewController;
@property (nonatomic, retain) UIViewController *historyViewController;
@property (nonatomic, assign) UIViewController *currentViewController;
@property (nonatomic, assign) UIViewController *profileViewController;
@property (nonatomic, retain) UIViewController *recentRequestViewControll

//首页.m

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {

NSLog(@"didSelectItem: %d", item.tag);
[self activateTab:item.tag];

}

-(void)activateTab:(int)index

{

switch (index) {
case 1:
if (myServicesViewController == nil) {

self.myServicesViewController=

[[MyServices alloc] initWithNibName:nil bundle:nil];
}

[self.view insertSubview:myServicesViewController.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = myServicesViewController;
break;
case 2:
if (historyViewController == nil) {
self.historyViewController =
[[History alloc] initWithNibName:nil bundle:nil];
}
[self.view insertSubview:historyViewController.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = historyViewController;
break;
case 3:
if (recentRequestViewController == nil) {
self.recentRequestViewController =
[[RecentRequest alloc] initWithNibName:nil bundle:nil];
}
[self.view insertSubview:recentRequestViewController.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = recentRequestViewController;
break;
case 4:
if (profileViewController == nil) {
self.profileViewController =
[[Profile alloc] initWithNibName:nil bundle:nil];
}
[self.view insertSubview:profileViewController.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = profileViewController;
break;
default:
break;
}
}


-(void)viewDidLoad

{

UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed: @"bg.jpg"]];
self.view.backgroundColor = background;
[myTabBar setSelectedItem:[myTabBar.items objectAtIndex:0]];
[self activateTab:1];
[super viewDidLoad];

}

点击任何选项卡 View 都没有改变谁能告诉我哪里出错了??

最佳答案

因为
[自激活标签:1];

你选择标签索引 1 这就是为什么每次你得到相同的标签时你都需要每次都传递选定的标签索引而不是修复。

我也找不到任何用于获取选择标签栏索引的标签栏选择方法。

关于objective-c - 点击选项卡栏项目 View 在 iphone 中没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8998724/

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