user3069029
user3069029

Reputation: 211

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.

Upvotes: 1

Views: 1587

Answers (1)

Greg
Greg

Reputation: 25459

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;

Upvotes: 4

Related Questions