我正在从uiview控制器添加tabbarcontroller。请检查我的代码:
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];
根据需要添加标签栏控制器。但现在我想添加一个按钮返回上一页,或者你可以说从添加它的viewcontroller中删除tabbar及其viewcontrollers。有人可以建议我怎么办? 请记住,我已经从viewcontroller添加了tabbarcontroller而不是app delegate。
问候
的Pankaj
答案 0 :(得分:0)
我已经拿了一个tabbar和alloc-init一次,然后我会显示&amp;隐藏在不同的UIView
s。所以没有必要删除&amp;一直分配。
显示标签栏
[self showTabBar:self.tabBarController];
隐藏标签栏
[self hideTabBar:self.tabBarController];
展示代码 - &gt;它将通过设置'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];
}
隐藏代码 - &gt;它会通过设置'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];
}
希望如果不想分配&amp;在申请期间一直释放。
感谢。
答案 1 :(得分:0)
只需将此方法放在AppDelegate.m
文件中,并在想要从superview中删除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类的对象调用上面的方法For Ex ..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setMainView];
我希望这对你有所帮助..