How to implement checkbox control in iphone programming?

Leave a Comment
Check box control implementation in iphone. This is the simple demo for implement check box in iphone. Here i will give you some code snippets as well as complete source code in iphone.

CheckboxViewController .h

#import <UIKit/UIKit.h>
@interface CheckboxViewController : UIViewController {
BOOL checkboxSelected;
IBOutlet UIButton *checkboxButton;
}
- (IBAction)checkboxButton:(id)sender;
@end
CheckboxViewController .m


#import "CheckboxViewController.h"
@implementation CheckboxViewController
- (IBAction)checkboxButton:(id)sender{
if (checkboxSelected == 0){
[checkboxButton setSelected:YES];
checkboxSelected = 1;
} else {
[checkboxButton setSelected:NO];
checkboxSelected = 0;
}
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


- (void)viewDidLoad {
checkboxSelected == 0;
    [super viewDidLoad];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

- (void)dealloc {
    [super dealloc];
}
@end
Output:

Download Source Code

 

0 comments:

Post a Comment