У меня проблема с скрытием панели навигации в контроллере панели вкладок.Начальная вкладка скрывается правильно, но любые последующие вкладки не будут скрывать свою панель навигации.Другая проблема, которую я имею, состоит в том, что тот же самый HTML-файл не загружается в двух других вкладках.Это действительно странное поведение, так как я получил HTML, чтобы нормально загружаться в других приложениях.
- (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
Я также пытался установить свойство в каждой функции делегата, используя этот новый .m Прежде чем вставить его, это распечатка журнала
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
НО ЕГО ВСЕ ЕЩЕ!Интересно отметить, что viewDidLoad не вызывается после нажатия на вторую вкладку.
@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