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 回答