显示一个视图控制器后的选项卡栏控制器

发布于 2025-01-07 08:06:01 字数 705 浏览 1 评论 0原文

我想问一下,在显示一个视图控制器后是否可以显示一个 tabbarcontroller。 我看过很多关于 tabbarcontroller 的教程,但它们都使用这一行放入 AppDelegate 中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self.window addSubview:tabController.view];
[self.window makeKeyAndVisible];
return YES;}

我想做的是首先显示一个视图控制器:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{     
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES; }

显示 viewController 后,用户必须单击一个按钮才能显示TABBARCONTROLLER 的另一个视图。如果可能的话,我该怎么做?

I would like to ask if it's possible to show a tabbarcontroller after I showed one view controller.
I've seen lots of tutorials about tabbarcontroller but they were all put in the AppDelegate using this line:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self.window addSubview:tabController.view];
[self.window makeKeyAndVisible];
return YES;}

What I would like to do is show one view controller first:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{     
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES; }

and after showing the viewController, the user will have to click a button to show another view with the TABBARCONTROLLER. If that's possible, how do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

婴鹅 2025-01-14 08:06:01

是的,您可以...在您的第一个控制器中,完成某些工作后,然后按 Tabbar 控制器。

示例:-

假设您通过子类化 UITabBarController 拥有 TabBarController 类。

- (void) doSomeJob
{
  if(true)
  {
     TabBarController *aTabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil];
     [self.navigationController pushViewController:aTabBarController animated:YES];
     [aTabBarController release];    
  }
}

编辑自定义标签栏:

.h文件

@interface TabBarController : UITabBarController<UITabBarControllerDelegate,    UINavigationControllerDelegate> 
{
    UITabBarController *tabController;
    UINavigationController *1NavController;
    UINavigationController *2hNavController;
}

@property (nonatomic, retain) UITabBarController *tabController;
@property (nonatomic, retain) UINavigationController *1NavController;
@property (nonatomic, retain) UINavigationController *2hNavController;

.m文件:

- (void)viewDidLoad
{
[super viewDidLoad];    

tabController = [[UITabBarController alloc] init];
tabController.delegate = self;
tabController.tabBar.backgroundColor = [UIColor clearColor];

//Add some tabs to the controller...
1ViewController *1ViewController = [[1ViewController alloc] initWithNibName: @"1ViewController" bundle: nil];
1NavController = [[UINavigationController alloc] initWithRootViewController:1ViewController];
1NavController.tabBarItem = [[UITabBarItem1 alloc] init];

2ViewController *aSearchViewController = [[2ViewController alloc] initWithNibName: @"2ViewController" bundle: nil];
2NavController = [[UINavigationController alloc] initWithRootViewController:2ViewController];
2NavController.tabBarItem = [[UITabBarItem2 alloc] init];

tabController.viewControllers = [NSArray arrayWithObjects: 1NavController,2NavController,nil];

[self.view addSubview:tabController.view];
}

您还需要相应地实现标签栏的委托方法....

Yes you can... in your first controller, after some job is completed then push the Tabbar controller.

Example:-

Assuming you have TabBarController class by sub classing UITabBarController.

- (void) doSomeJob
{
  if(true)
  {
     TabBarController *aTabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil];
     [self.navigationController pushViewController:aTabBarController animated:YES];
     [aTabBarController release];    
  }
}

EDITED custom tab bar :

.h file

@interface TabBarController : UITabBarController<UITabBarControllerDelegate,    UINavigationControllerDelegate> 
{
    UITabBarController *tabController;
    UINavigationController *1NavController;
    UINavigationController *2hNavController;
}

@property (nonatomic, retain) UITabBarController *tabController;
@property (nonatomic, retain) UINavigationController *1NavController;
@property (nonatomic, retain) UINavigationController *2hNavController;

.m file :

- (void)viewDidLoad
{
[super viewDidLoad];    

tabController = [[UITabBarController alloc] init];
tabController.delegate = self;
tabController.tabBar.backgroundColor = [UIColor clearColor];

//Add some tabs to the controller...
1ViewController *1ViewController = [[1ViewController alloc] initWithNibName: @"1ViewController" bundle: nil];
1NavController = [[UINavigationController alloc] initWithRootViewController:1ViewController];
1NavController.tabBarItem = [[UITabBarItem1 alloc] init];

2ViewController *aSearchViewController = [[2ViewController alloc] initWithNibName: @"2ViewController" bundle: nil];
2NavController = [[UINavigationController alloc] initWithRootViewController:2ViewController];
2NavController.tabBarItem = [[UITabBarItem2 alloc] init];

tabController.viewControllers = [NSArray arrayWithObjects: 1NavController,2NavController,nil];

[self.view addSubview:tabController.view];
}

Also you need to implement Tab bar's delegate methods accordingly....

ヅ她的身影、若隐若现 2025-01-14 08:06:01

我遇到了导航控制器和选项卡栏视图控制器的情况,但您需要视图控制器,所以我根据您的要求修改我的代码。检查n回复
首先在应用程序委托 .h 文件中初始化视图控制器和选项卡栏控制器
&给属性也像:

{
    IBOutlet FirstViewController * fvc;

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

比在.m文件中将视图控制器设置为视图,因为您要首先设置简单的视图控制器,例如:

fvc = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];


[self.window addSubview: fvc.view];

现在在这个视图控制器中,在您想要跳转到选项卡视图控制器用户的特定事件中:

    AppDelegate_iPhone *appDelegte_iPhone=(AppDelegate_iPhone*)[[UIApplication sharedApplication]delegate];                 
[[[appDelegte_iPhone viewController] view] removeFromSuperview];
[[appDelegte_iPhone window]addSubview:[[appDelegte_iPhone tabBarController]view]];  

  [[appDelegte_iPhone tabBarController]setSelectedIndex:0];

I had a situation with navigation controller and tab bar view controller but ur need is with view controller so i modify my code according to ur requirement.check n reply
first initialize view controller and tabbar controller both in app delegate .h file
& give property also like:

{
    IBOutlet FirstViewController * fvc;

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

than in .m file set the view controller to the view as u want to set simple view controller first, like :

fvc = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];


[self.window addSubview: fvc.view];

Now in the this view controller on the particular event where u want to jump to tabbar view controller user this :

    AppDelegate_iPhone *appDelegte_iPhone=(AppDelegate_iPhone*)[[UIApplication sharedApplication]delegate];                 
[[[appDelegte_iPhone viewController] view] removeFromSuperview];
[[appDelegte_iPhone window]addSubview:[[appDelegte_iPhone tabBarController]view]];  

  [[appDelegte_iPhone tabBarController]setSelectedIndex:0];
木森分化 2025-01-14 08:06:01

将 UITabBarController 保留为窗口的根视图控制器。将您的其他视图控制器呈现为模态视图控制器。关闭模态视图控制器以显示选项卡栏控制器。

Leave the UITabBarController as your window's root view controller. Present your other view controller as a modal view controller. Dismiss the modal view controller to reveal the tab bar controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文