简体   繁体   中英

How to hide button from one view controller to another

I knew this is a repeated question but i can't get solution for this.

How to hide button from one view controller to another view controller,

i got this code using nib file,

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

but i'm using storyboard, i tried this

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];

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

It's not work for me.

It doesn't work because the controls hasn't been create just after you call init.

You can hide the controls in, for example, viewDidLoad method. To do it you can create bool property in the view controller you want to hide the view:

@property BOOL hideButton;

And after initialisation change the property to true if you want to hide the button:

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

Next in viewDidLoad in ViewController class check is this flag set to true and if so hide the button:

if (self.hideButton)
    vc.checkBtn.hidden = YES;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM