0
votes

My app supports iOS8+ devices. I want to hide right Action button from navigation bar. By research I found following few workarounds:

1. Create Sub class of QLPreviewController and in ViewDidAppear SetRightBarButtonItems to zero.

public class PdfViewController : QLPreviewController
{
  public override void ViewDidAppear (bool animated)
    {
        base.ViewDidAppear (animated);
        NavigationItem.SetRightBarButtonItems (new UIKit.UIBarButtonItem[0], false);
    }
}

In this case problem is RightBarButtonItem appears and then disappears. In mean while user is able to click on that RightBarButtonItem button. I don't want this behavior.

2. Create UIViewController and add QLPreviewController as child ViewController.

void BtnShowPdf_Clicked (object sender, EventArgs e) {

    var dummyVC = new UIViewController ();
    var pdfVC = new PdfViewController ();

    dummyVC.AddChildViewController (pdfVC);
    dummyVC.View.AddSubview (pdfVC.View);
    dummyVC.NavigationItem.SetRightBarButtonItems (new UIBarButtonItem[0], false);

    dummyVC.EdgesForExtendedLayout = UIRectEdge.None;
    dummyVC.AutomaticallyAdjustsScrollViewInsets = false;
    dummyVC.View.BackgroundColor = UIColor.Clear;

    pdfVC.EdgesForExtendedLayout = UIRectEdge.None;
    pdfVC.AutomaticallyAdjustsScrollViewInsets = false;
    pdfVC.View.BackgroundColor = UIColor.Clear;
}

In this case If I set QLPreviewController it works as expected. But NavigationBar becomes more darker than default ViewController background color.

Dark Bar: http://screencast.com/t/bqVMv5qqGz

Needed clear background bar like: http://screencast.com/t/MUwE2VnxJ7

My questions are:

A) I would like to know which is the correct way to hide right navigation bar button as per Apple guidelines ? If you have correct solution then those are also appreciated.

B) Also Can you please suggest solution(s) for #1 Or #2 ?

1

1 Answers

0
votes

Pretty sure you can do this:

override func viewWillAppear(_ animated: Bool)
    {
        super.viewWillAppear(animated)

        self.navigationItem.rightBarButtonItems = nil
    }