简体   繁体   中英

Xamarin.ios - Back/Done button when displaying PDFs in a web view

I am creating an app which shows web pages in web view. Web page has PDFs on it. When i click on PDF link, it shows PDF file but there is no back button to go back to app after viewing the PDF. Is there a way of displaying a done/back button when displaying PDFs in a web view?

Any help would be much appreciated, Thanks in advance!

If you use Navigation in your ViewController you can rewrite the backAction

public override void ViewWillAppear(bool animated)
{
  base.ViewWillAppear(animated);

  UIBarButtonItem itemleft = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, this, new Selector("BackAction"));
  this.NavigationItem.LeftBarButtonItem = itemleft;

}
Export("BackAction")]
void BackAction()
{
  if (webView.CanGoBack)
  {
    webView.GoBack();
  }

  else
  {
    this.NavigationController.PopViewController(true);
  }
}

You couldn't add a button on html in iOS platform.So I think this is a friendly solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM