我知道这是一个重复的问题,但我无法为此解决方案。

如何将按钮从一个视图控制器隐藏到另一个视图控制器,

我使用笔尖文件获得了此代码,

ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
vc.checkBtn.hidden = YES;

但是我正在使用情节提要,我尝试了这个
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];

ViewController *vc = [[ViewController alloc] init];
vc = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
vc.checkBtn.hidden = YES;

这对我不起作用。

最佳答案

它不起作用,因为尚未在调用init之后立即创建控件。

您可以将控件隐藏在例如viewDidLoad方法中。为此,您可以在要隐藏视图的视图控制器中创建bool属性:

@property BOOL hideButton;

初始化后,如果要隐藏按钮,请将属性更改为true:
ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
vc.hideButton = YES;

接下来在ViewController类的viewDidLoad中检查此标志是否设置为true,如果是,则隐藏按钮:
if (self.hideButton)
    vc.checkBtn.hidden = YES;

关于ios - 如何将按钮从一个 View Controller 隐藏到另一个,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21876082/

10-14 14:05
查看更多