从uiviewcontroller中删除tabbar控制器
问题描述:
我正在从uview控制器中添加一个tabbarcontroller。请检查我的代码:从uiviewcontroller中删除tabbar控制器
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NSMutableArray *arrControllers = [[NSMutableArray alloc] init];
for(int i = 0; i<arrTabs.count;i++){
NSArray *arr = [arrTabs objectAtIndex:i];
if([[arr objectAtIndex:0] isEqualToString:@"PICS"]){
picTabViewController *pics = [[picTabViewController alloc] initWithNibName:@"picTabViewController" bundle:nil];
UINavigationController *picsNVC = [[UINavigationController alloc] initWithRootViewController:pics];
picsNVC.tabBarItem.image = [UIImage imageNamed:@"tab-news.png"];
picsNVC.tabBarItem.title = [arr objectAtIndex:1];
[arrControllers addObject:picsNVC];
}
if([[arr objectAtIndex:0] isEqualToString:@"MAP"]){
mapTabViewController *maps = [[mapTabViewController alloc] initWithNibName:@"mapTabViewController" bundle:nil];
UINavigationController *mapsNVC = [[UINavigationController alloc] initWithRootViewController:maps];
mapsNVC.tabBarItem.image = [UIImage imageNamed:@"tab-news.png"];
mapsNVC.tabBarItem.title = [arr objectAtIndex:1];
[arrControllers addObject:mapsNVC];
}
if([[arr objectAtIndex:0] isEqualToString:@"HTML"]){
htmlTabViewController *html = [[htmlTabViewController alloc] initWithNibName:@"htmlTabViewController" bundle:nil];
UINavigationController *htmlNVC = [[UINavigationController alloc] initWithRootViewController:html];
htmlNVC.tabBarItem.image = [UIImage imageNamed:@"tab-news.png"];
htmlNVC.tabBarItem.title = [arr objectAtIndex:1];
[arrControllers addObject:htmlNVC];
}
}
tabBarController.viewControllers = arrControllers;
self.tabBarController.selectedIndex = 0;
[self.view.window addSubview:tabBarController.view];
根据需要添加标签栏控制器。但是现在我想添加一个按钮返回到上一页,或者您可以说从添加它的视图控制器中删除tabbar及其视图控制器。有人可以建议我怎么做?
请记住,我已经从viewcontroller中添加了tabbarcontroller,而不是app delegate。
问候
潘卡
答
我已经采取了一个的TabBar和Alloc-INIT一次,然后我会告诉&隐藏在不同的UIView
秒。
因此,无需一直删除& alloc。
显示的TabBar
[self showTabBar:self.tabBarController];
隐藏的TabBar
[self hideTabBar:self.tabBarController];
代码显示 - >它会自动通过设置 'Y' 出现::
- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, 519, view.frame.size.width, view.frame.size.height)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
}
else
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 519)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
}
[UIView commitAnimations];
}
代码隐藏 - >它会通过设置'Y'自动消失::
- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, 568, view.frame.size.width, view.frame.size.height)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
}
else
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 568)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
[UIView commitAnimations];
}
希望它会帮助你,如果不想在应用程序中一直分配&版本。
谢谢。当你想从上海华删除tabbarcontroller并设置其它视图作为parentviewController
-(void)setMainView
{
yourViewController *masterViewController = [[[yourViewController alloc] initWithNibName:@"yourViewController" bundle:nil] autorelease];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.navigationController.navigationBar.hidden=YES;
self.window.rootViewController = self.navigationController;
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
,并调用上面的方法与AppDelegate类对于防爆的对象
答
只是把这个方法AppDelegate.m
文件并调用此方法..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setMainView];
我希望这有助于你..
没有得到你。你可以用图像来阐述这个吗? – 2013-03-07 10:58:18
我需要在可以删除完整标签控制器的tabcontroller的第一页(uiviewcontroller)上添加一个按钮。 – pankaj 2013-03-07 11:01:22
从整个应用程序? – 2013-03-07 11:03:55