I have a UINavigationController(a) that pushes a UIViewController(b) onto the stack. (b) contains a UITabBarController(c). (c) has 5 tabs and any of these ViewControllers(d,e,f,g,h) needs to be able to pop (b) off the stack.
I've tried [[self.parentViewController navigationController] popViewControllerAnimated:YES]; among many other things, none of which seem to work. Any ideas?
Edit:
.h file:
@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
notice how I have a major hack in this line:
self.view = self.tabBarController.view;