0

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

当前的实现只显示http://www.google.com而没有UIToolBar. 我究竟做错了什么?

登录WebviewController.h

#import <UIKit/UIKit.h>

@interface LoginWebViewController : UIViewController

@end  

登录WebviewController.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
4

1 回答 1

0

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

检查作为初始视图控制器的 Storyboard 文件。如果这是正常的UIViewController,您需要将 aUINavigationViewController作为您的 initialViewController。但是,我建议UIToolbar您在其中添加一个LoginWebViewController并在其中设置按钮。如果您没有在您的应用程序中进行任何导航,那就太好了(因为它是一个基于 webview 的应用程序)

于 2014-12-27T23:54:20.183 回答