2

印刷ボタンを非表示にするにはどうすればよいですかQLPreviewController

ではIOS5、このコードは機能します

QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.delegate = self;
previewController.currentPreviewItemIndex = _fileidx;
[[self navigationController] pushViewController:previewController animated:YES];
[previewController.navigationItem setRightBarButtonItem:nil];

しかし、IOS6 ではそうではありません。

4

2 に答える 2

2

ナビゲーションアイテムをチェックして削除するタイマーを作成することで、なんとかできました

myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
             target:self
             selector:@selector(hideRightButton:)
             userInfo:nil
             repeats:YES];
- (void)hideRightButton:(NSTimer *)timer {
    [self inspectSubviewsForView:self.view];
}
- (void)inspectSubviewsForView:(UIView *)view
{
    for (UIView *subview in view.subviews)
    {
        NSLog(@"class detected %@",[subview description]);
        if ([subview isKindOfClass:[UINavigationBar class]])
        {
            UINavigationBar *bar = (UINavigationBar *)subview;
            if ([[bar items] count] > 0)
            {
                UINavigationItem *navItem = [[bar items] objectAtIndex:0];
                [navItem setRightBarButtonItem:nil];
                {
                }

                if ([subview isKindOfClass:[UIView class]] && [[subview subviews] count] > 0)
                {
                    [self inspectSubviewsForView:subview];
                }
            }
        }
        [self inspectSubviewsForView:subview];
    }
}
于 2013-02-28T11:09:56.890 に答える
0

問題は、ドキュメントの準備ができるとボタンが再生成されたように見えることです。「準備完了」を実際に定義することはできませんが、テストアプリを作成し、いくつかのことに気づきました。

  • NavigationItemの右バーボタンの設定はiOS6では機能しません
  • ビュー階層をスキャンしてUIToolbarのインスタンスを検索し、ツールバーのボタンを設定すると機能します。

上記のハックは、表示されているドキュメントが十分に「準備ができている」場合にのみ機能します。大きなドキュメントは時間がかかります。私は2段階の解決策を思いついた:

  • ナビゲーションアイテムを検索する
  • NSTimerを使用して常に非表示にします。

ここにいくつかのコードがあります:

これはViewDidAppear()からのものです:

ボタンを隠し続けるタイマーを設定します。

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 );
} );
}

これにより、ナビゲーションアイテムが検索されます。

/// <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;

                    }

               }

          }
于 2012-11-13T12:11:44.637 に答える