Reputation: 2836
I have a very simple method, but it does not work. Ultimately, from input YES, I want to get NO and reverse.
-(void)myMethod:(BOOL)ys{
if (ys==YES) {
myLabel.hidden=NO;
myButton.hidden=NO;
}{
myLabel.hidden=YES;
myButton.hidden=YES;
}
}
Can you guys help me to correct and shorten the code? Thanks
Upvotes: 0
Views: 1478
Reputation: 2272
If we are trying to make it short...`
-(void)myMethod:(BOOL)ys{
myLabel.hidden = myButton.hidden = !ys;
}
Upvotes: 0
Reputation: 249
Maybe this is a litle easier:
-(void)myMethod:(BOOL)ys{
myLabel.hidden = !ys;
myButton.hidden = !ys;
}
Upvotes: 3
Reputation: 120
-(void)myMethod:(BOOL)visible
{
[myLabel setHidden:!visible];
[myButton setHidden:!visible];
}
The code should be working. However, your code is not working is probably because you did not set the referencing outlets for your label and button (If you created them with interface builder).
Referencing outlets should be set like this. Otherwise, the complier would not know if the button you want to hide is the button on the interface.
If you created the button/label with codes, check if you have them released before you are trying to set them visible or not please.
Upvotes: 3
Reputation: 365
-(void)myMethod:(BOOL)ys{
if (ys) {
myLabel.hidden=NO;
myButton.hidden=NO;
} else {
myLabel.hidden=YES;
myButton.hidden=YES;
}
}
Upvotes: 0