I am having a problem with hiding the navigation bar in a tab bar controller. The initial tab hides correctly but any successive tabs will not hide their Nav bar. The other problem I am having is the same html file will not load in the other two tabs. This is really strange behavior as I have gotten html to load just fine in other applications.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions{
// Override point for customization after application launch.
//create views
testView *viewer1 = [[testView alloc] init];
testView2 *viewer2 = [[testView2 alloc] init];
testView3 *viewer3 = [[testView3 alloc] init];
// Put viewers in a Nav controllers
UINavigationController *navCon1 = [[UINavigationController alloc] init];
[navCon1 setViewControllers:[NSArray arrayWithObject:viewer1] animated:NO];
UINavigationController *navCon2 = [[UINavigationController alloc] init];
[navCon1 setViewControllers:[NSArray arrayWithObject:viewer2] animated:NO];
UINavigationController *navCon3 = [[UINavigationController alloc] init];
[navCon1 setViewControllers:[NSArray arrayWithObject:viewer3] animated:NO];
// Put controllers in a tab bar
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = [NSArray arrayWithObjects:navCon1,navCon2,navCon3, nil];
//Release all the stuff
[viewer1 release]; [viewer2 release]; [viewer3 release];
//[navCon1 release]; [navCon2 release]; [navCon3 release];
[self.window addSubview:tabBar.view];
[self.window makeKeyAndVisible];
return YES;
}
// Test views are just a UIWebView as a sub view built in IB and then connected to the //IBOutlet and connected to be the delegate.
//Here is TestView.m
@implementation testView
@synthesize webView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.navigationController.navigationBarHidden = YES;
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"HTMLsupport"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.webView = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
I have also tried to set the property in every delegate function using this new .m
Before I paste it this is the log print out
2011-08-14 04:23:23.857 startRipple2[1613:b303] viewDidLoad
[Switching to process 1613 thread 0xd603]
2011-08-14 04:23:23.859 startRipple2[1613:b303] viewWillAppear
2011-08-14 04:23:23.860 startRipple2[1613:b303] viewDidAppear
2011-08-14 04:23:23.860 startRipple2[1613:b303] its hidden
[Switching to process 1613 thread 0x12103]
2011-08-14 04:23:27.270 startRipple2[1613:b303] viewWillAppear
2011-08-14 04:23:27.271 startRipple2[1613:b303] viewDidAppear
2011-08-14 04:23:27.273 startRipple2[1613:b303] its hidden
BUT ITS STILL THERE! Something interesting to note is viewDidLoad is not called after clicking on the second tab.
@synthesize webView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {// Custom initialization
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBarHidden = YES;
NSString *path = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html" inDirectory:@"tabA"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
webView.scalesPageToFit = YES;
// Do any additional setup after loading the view from its nib.
NSLog(@"viewDidLoad");
}
- (void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBarHidden = YES;
NSLog(@"viewWillAppear");
}
- (void)viewDidAppear:(BOOL)animated{
//self.navigationController.navigationBarHidden = YES;
NSLog(@"viewDidAppear");
if (self.navigationController.navigationBarHidden) {
NSLog(@"its hidden");
}
if (!self.navigationController.navigationBarHidden){
NSLog(@"its there...");
}
}
- (IBAction)mySelector:(id)sender {
NSLog(@"You touched me THERE!");
[self.webView goBack];
[self.navigationController setNavigationBarHidden:YES];
}
-(void)awakeFromNib{
NSLog(@"awakeFromNib");
[self.navigationController setNavigationBarHidden:YES];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//int count =0;
//count = count +1 ;
//NSLog([NSString stringWithFormat:@"count %d",count]);
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
/*if (navigationType == UIWebViewNavigationTypeLinkClicked || navigationType == UIWebViewNavigationTypeFormSubmitted) {
[self.navigationController setNavigationBarHidden:NO];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(mySelector:)];}*/
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.webView = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
First theres an mistake in your code. In your applicationDidFinishLaunching you always set the viewcontrollers to navcon1 and not to navcon1, then navcon2, then navcon3.
Fix this and check if the problem remains