uitabbarcontroller/uitabbar 在基于导航的项目中 [英] uitabbarcontroller / uitabbar in navigation based project

查看:13
本文介绍了uitabbarcontroller/uitabbar 在基于导航的项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了基于导航的项目.在第二个屏幕中我想添加 uitabbarcontroller.任何人都可以建议我如何做到这一点.

I have created navigation based project. and in second screen i want to add uitabbarcontroller. so can any one suggest how i do this.

我已经做了很多搜索,但还没有成功.所以请您提供一个简单的示例.我已经尝试过下面的讨论,但我认为这不是一个好方法.

i already did lot of search but no success yet. so please can you provide a simple sample of this. i already tried below discussion but i think its not a good approach.

使用 TabBar 的基于导航的应用程序

谢谢

推荐答案

其实这才是正确的做法.不正确的一件事是控制器的分配位置.这发生在前一个控制器中,即进行推送的控制器,但应该分配在负责的对象 TabBarController 中.

Actually this is the correct approach. The one thing that is not correct is where the controllers are allocated. This is happened in the previous controller, the one that is making the push, but should be allocated in the object that is responsible, the TabBarController.

当您实现显示 UITabBarController 的操作时,请编写以下代码:

When you implement your action to show the UITabBarController make the following code:

- (void) theAction {
   SomeTabBarControllerSubClass *controller = [[SomeTabBarControllerSubClass alloc] init];
   [self.navigationController pushViewController:controller animated:YES];
   [controller release];
}

那么当你实现 SomeTabBarControllerSubClass 类时:
(.h)

Then when you implement the SomeTabBarControllerSubClass class:
(.h)

@interface SomeTabBarControllerSubClass : UITabBarController {
   UIViewController *first;
   UIViewController *second;
}

@end

(.m)

@implementation SomeTabBarControllerSubClass

- (void) viewDidLoad {
   first = [[UIViewController alloc] init]; //Or initWithNib:
   second = [[UIViewController alloc] init];

   first.view.backgroundColor = [UIColor greenColor] //Just example
   second.view.backgroundColor = [UIColor redColor] //Just example
   first.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];

   self.viewControllers = [NSArray arrayWithObjects:first,second,nil];
}

- (void) dealloc {
   [first dealloc];
   [second dealloc];
   [super dealloc];
}

@end

这篇关于uitabbarcontroller/uitabbar 在基于导航的项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆