我是通过自定义UIButton为iPad应用程序创建的。
现在由于特定原因,我想隐藏这些按钮。为此,我使用以下代码:
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];
}
}
}
}
}
但我无法在此阵列中获取自定义按钮。即使窗口/屏幕上出现的视图有这些按钮,它也只保持空白。
我哪里错了?请指导我。
答案 0 :(得分: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];