I am having a strange problem that I don't understand, and therefore don't know where to start debugging.
FIRSTLY, THE REQUIREMENT
I have a UISplitView. The Master view contains a table which loads different views into the Detail view. For one table cell, I want a website loaded full screen. Therefore, rather than hiding the Master view and resizing the Detail view, I am presenting a view controller. It is with this that I have the problem.
THE CODE
Below is the code i currently have - greatly stripped down to avoid clutter
-- MASTER VIEW --
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ProjectWebViewController *detailView=[[ProjectWebViewController alloc] init];
UIViewController *localdetailViewController = detailView;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:localdetailViewController];
[self presentViewController:navController animated:YES completion:nil];
}
I then have the following in the presented view controller
-- PRESENTED VIEW CONTROLLER --
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[[self view] addSubview:webView];
UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:@selector(closeSelf)];
[[self navigationItem] setLeftBarButtonItem:backBtn];
}
-(void)closeSelf
{
[[self navigationController] dismissViewControllerAnimated:YES completion:nil];
}
THE PROBLEM
The above works well with one exception. The back button i added to the navigation bar does nothing when clicked. However, if i click any white space on the web page that is loaded, the back button works. I have tested this many times. Even if I click some white space and then click a link on the web page, the back button stops working again until more white space is clicked on the current web page.
Can anyone point me in right direction?
Thanks
UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:@selector(closeSelf)];
target should be set to self instead of nil
UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(closeSelf)];