I'm trying to build an app that has a webview with a top UIToolBar
. This app is meant for internal use at our company and I was tasked with building this. This particular webview comes up if a user wants to read the FAQ, which are loaded from our internal website. This webview loads as a modal and needs a button in the UIToolBar
to dismiss it. However, I'm not having any luck.
The current implementation just displays http://www.google.com without the UIToolBar
. What am I doing wrong?
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
Probably your LoginWebViewController
won't be a part of UINavigationViewController
.
Check your Storyboard file which is the initial view controller. If it's a normal UIViewController
you need to put a UINavigationViewController
as your initialViewController. But instead of that I'll suggest adding a UIToolbar
in your LoginWebViewController
and set the buttons in it. It'll be good, if you are not doing any navigation in your app (As it's a webview based app)