The issue is that the button seems to be regenerated once the document is ready. I cannot really define "ready" but I wrote a test app and noticed a couple of things:
- Setting the NavigationItem's right bar buttons doesn't work in iOS6
- Scanning the view hierachy and search for an instance of UIToolbar and set the toolbar's buttons works.
The above hack only works if the document being shown is "ready" fast enough. Big documents take longer.
I came up with a two step solution:
- Search the navigation item
- Constantly hide it using NSTimer.
Here's some code:
This is from ViewDidAppear():
Setup a timer that keeps on hiding the button.
NSTimer oTimer = NSTimer.CreateRepeatingTimer(0.2, this.HidePrintButton);
NSRunLoop.Current.AddTimer(oTimer, NSRunLoopMode.Default);
private void HidePrintButton()
{
if(this.oNavItem == null)
{
return;
}
this.InvokeOnMainThread(
delegate {
this.oNavItem.SetRightBarButtonItems( new UIBarButtonItem[0], false );
} );
}
This searches the navigation item:
/// <summary>
/// Finds the first navigation item inside a view hierachy.
/// </summary>
/// <param name='oCurrentView'>the view to start searching from</param>
/// <param name='oItem'>will be set if the navigation item was found</param>
public static void FindNavigationItem(UIView oCurrentView, ref UINavigationItem oItem)
{
if(oItem != null || oCurrentView == null || oCurrentView.Subviews == null || oCurrentView.Subviews.Length <= 0)
{
return;
}
// Check if a UINavigationBar was found. This will contain the UINavigationItem.
if(oCurrentView is UINavigationBar)
{
UINavigationBar oBar = (UINavigationBar)oCurrentView;
if(oBar.Items != null && oBar.Items.Length > 0)
{
oItem = oBar.Items[0];
}
return;
}
// Recursively loop all sub views and keep on searching.
foreach (var oSubView in oCurrentView.Subviews)
{
FindNavigationItem(oSubView, ref oItem);
if(oItem != null)
{
break;
}
}
}
but in IOS6, it doesn't
. Do you get an error or exception? Or does everything run fine, but the print button is just not hidden? – Alost