UIToolBar not displaying



我正在尝试构建一个具有顶级UIToolBar的Web视图的应用程序。这个应用程序是为我们公司内部使用的,我的任务是构建这个。如果用户想要阅读从我们的内部网站加载的常见问题解答,则会出现此特定网络视图。此 Web 视图作为模式加载,需要UIToolBar中的按钮来关闭它。但是,我没有任何运气。

当前的实现仅显示 http://www.google.com 而不显示UIToolBar。我做错了什么?

LoginWebviewController.h

#import <UIKit/UIKit.h>
@interface LoginWebViewController : UIViewController
@end  

LoginWebviewController.m

#import "LoginWebViewController.h"
@interface LoginWebViewController ()
@end
@implementation LoginWebViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Log in";
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(barButtonBackPressed:)];
    UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 1024,768)];
    NSString *url=@"http://www.google.com";
    NSURL *nsurl=[NSURL URLWithString:url];
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
    [webview loadRequest:nsrequest];
    [self.view addSubview:webview];
}
-(void)barButtonBackPressed:(id)sender{
    [self dismissModalViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

可能你的LoginWebViewController不会成为UINavigationViewController的一部分。

检查作为初始视图控制器的情节提要文件。如果是普通UIViewController则需要放置一个UINavigationViewController作为初始视图控制器。但取而代之的是,我建议在LoginWebViewController中添加一个UIToolbar并在其中设置按钮。如果您没有在应用程序中进行任何导航,那就太好了(因为它是基于Web视图的应用程序)

最新更新