문제

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