ios - 如何在 objective-c 中的其他 View Controller 中隐藏按钮

标签 ios objective-c xib

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NewsScreen *news=[[NewsScreen alloc] initWithNibName:@"NewsScreen" bundle:nil];

    if (tabBarController.selectedIndex==2) {

        [news.btn setHidden: YES];

    }
    NSLog(@"%@", tabBarController);
}

我想隐藏来自另一个 View Controller 的按钮。

最佳答案

    -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {

            if (tabBarController.selectedIndex==2) 
            {
              NSUInteger *index=value; //assign value here
              UINavigationController *nv = [[tabBarController viewControllers] objectAtIndex:index];//index of your NewsScreen controller
              NSArray *array =[nv viewControllers];

              for (ViewController *vc in array)
              {
                if ([vc isKindOfClass:[NewScreen class]])
                {
                  [vc.btn setHidden:YES];
                }
              }

            }
            NSLog(@"%@", tabBarController);
        }

关于ios - 如何在 objective-c 中的其他 View Controller 中隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37916158/

相关文章:

ios - 使用 Storyboard中容器 View Controller 的数据初始化 View Controller

ios - .xib 文件中的多语言标签更改。

ios - 每当我尝试将 NSUserDefualts 保存到 NSMutableArray 时,它就会崩溃

iphone - 如何删除以前版本的 iPhone 应用程序存储的所有文件?

objective-c - Cocoa 创建临时文件夹/目录来保存文件

ios - 当充满地址簿信息的 UITableView 向下滚动时,应用程序崩溃

xcode - iOS应用程序中确实需要MainWindow.xib吗?

ios - 运行时 Storyboard中设置的 UIButton 标题丢失

ios - 在 ios 中从 box cloud (box.com) 访问用户数据

ios - 为什么用swift录制后听不到音乐?