1

iPadアプリケーション用のカスタムUIButtonで作成しました。

特定の理由から、これらのボタンを非表示にしたいと思います。そのために、次のコードを使用しています。

NSMutableArray *viewArray = [[NSMutableArray alloc] init];

    // Get all the windows
    for (UIWindow *window in [[UIApplication sharedApplication] windows])
    {
      // check for main screen
      if (![window respondsToSelector:@selector(screen)] ||
          [window screen] == [UIScreen mainScreen])
      {

        // check for all the subviews available in window
        for (UIView * view in [window subviews]) {

          // check whether it supports this method
          if ([view respondsToSelector:@selector(isKindOfClass:)]) {

            // type cast to button
            //          UIButton *btn = (UIButton *)view;

            // if its type of my custom button class
            if ([[view class] isKindOfClass:[DINNextLTProBoldButton class]]) {

              // hide view and add to array
              [view setHidden:YES];
              [viewArray addObject:view];
            }
          }
        }
      }
    }

しかし、この配列でカスタム ボタンを取得できません。ウィンドウ/画面に表示されているビューにそれらのボタンがあると思っても、空のままです。

どこが間違っているのですか?私を案内してください。

4

1 に答える 1

1

これを試してください(テストされていませんが、基本的なアイデアが得られます)

- (void)hideViewOfClass:(Class)clazz inHeirarchyOfView:(UIView *)view
{
    for (UIView *subview in [view subviews])
    {
        if ([subview isKindOfClass:clazz])
            subview.hidden = YES;
        else 
            [self hideViewOfClass:clazz inHeirarchyOfView:subview];
    }
}

最初にこの関数を次のように呼び出します。

for (UIWindow *window in [[UIApplication sharedApplication] windows])
    [self hideViewOfClass:[DINNextLTProBoldButton class] inHeirarchyOfView:window];
于 2012-08-23T11:53:54.663 に答える