Home Tutorial Iphone Examples HIDE BUTTON iPHONE

 
 

Share on Google+Share on Google+
HIDE BUTTON iPHONE
Posted on: November 27, 2009 at 12:00 AM
Advertisement
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.

HIDE BUTTON iPHONE

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;
    IBOutlet UITextField *textfield;

}
@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) IBOutlet UITextField *textfield;

-(IBAction) hidebutton:(id)sender;

@end


button_exampleViewController.m

#import "button_exampleViewController.h"

@implementation button_exampleViewController
@synthesize button, textfield;

-(IBAction) hidebutton:(id)sender
{
    if([textfield.text isEqualToString: @""]){ 
        button.hidden = YES; 
     
} else { 
        button.hidden = NO;   
     

    NSLog( @"%@", textfield.text );
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [button release];
    [textfield release];
    [super 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.

Download code

Advertisement

Related Tags for HIDE BUTTON iPHONE:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 27, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com