Basically, buttons are used to give an action to the program to proceed further.. but sometimes there could be some conditions when we wanted to restrict the user from clicking the button.
Basically, buttons are used to give an action to the program to proceed further.. but sometimes there could be some conditions when we wanted to restrict the user from clicking the button.Basically,buttons are used to give an action to the program to proceed further.. but sometimes there could be some conditions when we wanted to restrict the user from clicking the button. In other way we can say that we are hiding button from the users until and unless the condition is true or he provides the sufficient information.
In cocoa we can do this with the help of isEqualToString: , basically it is a comparing string. To hide the button we write button.hidden = YES;
In this example we have used isEqualToString to compare the textfield value that means if the value of textfield is equal to null or not.
Let's find out the code...
button_exampleViewController.h
#import <UIKit/UIKit.h> @interface button_exampleViewController : UIViewController { IBOutlet UIButton *button; } -(IBAction) hidebutton:(id)sender; @end |
button_exampleViewController.m
#import "button_exampleViewController.h" @implementation button_exampleViewController -(IBAction) hidebutton:(id)sender - (void)didReceiveMemoryWarning { - (void)viewDidUnload { - (void)dealloc { @end |
In the foregoing example.. we have a textfield and a button. And on the button action, we have written a code that will hide the button ..if the value of textfield is equal to null as in given image.