Вопрос

I need to make a Button optional based on data coming from the server. It's easy when building UI programmatically. Like,

if ( flag == 1)
   {
       // Build the UIButton
   }

But I am new to storyboard and company wants to build the UI this way. So I was wondering how to make the button optional? Thanks in advance.

Это было полезно?

Решение

You can do it like this:

In your .h file declare your property

@property(nonatomic, weak) IBOutlet UIButton *yourBtn;

Link this property to your button in storyboard

In your .m file

-(void)viewDidLoad
{
 [super ViewDidLoad];
 [self.yourBtn setHidden:YES];
}

Later on in your code if you need to enable your button just call

[self.yourBtn setHidden:NO];

Другие советы

Assuming you're just trying to hide/show a button based on that condition:

[button setHidden:NO];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top