2015-07-01 133 views
0

在我的应用程序中,我添加了一个新的控制器xib文件。我有一个Web视图,显示一些HTML数据。现在的问题是它没有在屏幕上的任何位置显示导航栏,但它显示了Web视图中的数据。我可以在xib文件中看到导航栏。下面是在.m文件的代码..iOS ::导航栏不显示在iOS中

#import "TechTermViewController.h" 
    #import "PictureViewController.h" 

    @implementation TechTermViewController 

@synthesize mydef; 
@synthesize defhtml; 
@synthesize appDelegate; 
@synthesize myWebView; 
@synthesize randomObject; 
@synthesize preferences; 



- (void)loadView { 

    // the base view for this view controller 
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    contentView.backgroundColor = [UIColor whiteColor]; 

    // important for view orientation rotation 
    contentView.autoresizesSubviews = YES; 
    contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
    self.view = contentView; 
    [contentView release]; 

    //Initialize the WebView ----------------------------------------------------------- 
    CGRect webFrame = [[UIScreen mainScreen] applicationFrame]; 
    // webFrame.origin.y += kTopMargin + 5.0; // leave from the URL input field and its label 
    //webFrame.origin.y -= 0.0; 
    myWebView = [[UIWebView alloc] initWithFrame:webFrame]; 
    myWebView.backgroundColor = [UIColor blackColor]; 
    myWebView.backgroundColor = [UIColor whiteColor]; 
    myWebView.scalesPageToFit = YES; 
    // myWebView.detectsPhoneNumbers = NO; 
    myWebView.dataDetectorTypes = UIDataDetectorTypeLink; 
    myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
    myWebView.delegate = self; 

    [self.view addSubview: myWebView]; 


    [self loadDefHTML:YES]; 
    //[[self navigationController] setNavigationBarHidden:NO animated:YES]; 
} 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self loadDefHTML:YES]; 

    //[[self navigationController] setNavigationBarHidden:NO animated:YES]; 

} 


//make it happen 
- (void)viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:animated]; 

    [self loadDefHTML:YES]; 

    //[[self navigationController] setNavigationBarHidden:NO animated:YES]; 
} 

//Remove the toolbar if we are disappearing 
- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [myWebView stopLoading]; 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 




- (IBAction) doDone:(id)sender { 
    if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:) ]) { 
     [self dismissViewControllerAnimated:YES completion:nil]; 
    } 
    else { 
     [[self parentViewController] dismissModalViewControllerAnimated:YES]; 
    } 
} 

XIB ::

enter image description here

任何想法?

+0

如果我删除loadview方法,那么它显示导航栏,但不是web视图数据....为什么这样? – Anjali

+0

myWebView.scalesPageToFit = YES; 检查,也许这是原因。 –

回答

0

问题在于引用webview的出口。它没有设置为文件的所有者。定义了插座并删除了loadview方法后,它就可以工作。