gpt4 book ai didi

iphone - 从 UINavigationController 弹出一个包含 UITabBarController 的 UIViewController

转载 作者:行者123 更新时间:2023-11-29 11:21:43 26 4
gpt4 key购买 nike

我有一个 UINavigationController(a) 将 UIViewController(b) 压入堆栈。 (b) 包含一个 UITabBarController(c)。 (c) 有 5 个选项卡,这些 ViewControllers(d,e,f,g,h) 中的任何一个都需要能够从堆栈中弹出 (b)。

我试过 [[self.parentViewController navigationController] popViewControllerAnimated:YES];除其他外,这些似乎都不起作用。有什么想法吗?

编辑:

.h文件:

@interface MATabViewController : UIViewController<UITabBarControllerDelegate> {
UIViewController *ref;
}

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UIImageView *imgViewFooter;

@end

.m:

#import "MATabViewController.h"

@implementation MATabViewController
@synthesize tabBarController = _tabBarController;
@synthesize imgViewFooter;

- (void)viewDidLoad
{
[super viewDidLoad];

self.view = self.tabBarController.view;

self.tabBarController.delegate = self;
self.imgViewFooter.frame = CGRectMake(0.0f, 395.0f, 320.0f, 64.0f);
[self.tabBarController.view addSubview:self.imgViewFooter];
self.tabBarController.selectedIndex = 0;

ref = [[self.tabBarController viewControllers] objectAtIndex:0];
}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

NSInteger index = [[tabBarController viewControllers] indexOfObject:viewController];

switch (index) {
case 0:
self.imgViewFooter.image=[UIImage imageNamed:@"footer_full.png"];
break;
case 1:
self.imgViewFooter.image=[UIImage imageNamed:@"footer_full.png"];
break;
case 2:
self.imgViewFooter.image=[UIImage imageNamed:@"footer_full.png"];
break;
case 3:
self.imgViewFooter.image=[UIImage imageNamed:@"footer_full.png"];
break;
case 4:
self.imgViewFooter.image=[UIImage imageNamed:@"footer_full.png"];
break;

default:
break;
}
return YES;
}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (ref != viewController) {
[ref viewDidDisappear:YES];
ref = viewController;
[viewController viewDidAppear:YES];
}
}

@end

请注意我在这一行中有一个重大的破解:

self.view = self.tabBarController.view;

最佳答案

我遇到过类似的问题(如果我得到这个问题)。您可以将 UIViewController (b) 声明为 UITabBarController 的子类吗?请注意,UITabBarControllerUIViewController 的子类,因此您可以继续将其用作普通的 UIViewController。这样,您将在单个 Controller 中拥有 (b) 和 (c)。
现在 [self.navigationController popViewController]; 应该可以工作了。
至少,我是这样解决的。

关于iphone - 从 UINavigationController 弹出一个包含 UITabBarController 的 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6767975/

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