Make radio Button list in iphone?

Leave a Comment
Make radio button list in iphone is very simple and easy to create it. Here i made radio button list for selecting gender Like male and female . You can create your choice radio buttons in it. Code snippets and complete source code is also given below.

ViewController.h
@class UICheckbox;
#import <UIKit/UIKit.h>
#import "GSRadioButtonSetController.h"
#import "AppDelegate.h"
@interface ViewController : UIViewController<GSRadioButtonSetControllerDelegate,UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
{
    NSMutableArray *a;
    AppDelegate *appdelegate;
}
@property(nonatomic, retain) UIToolbar *keyboardToolbar;
@property (nonatomic, strong) IBOutlet GSRadioButtonSetController * radioButtonSetController;
@property (strong, nonatomic) IBOutlet UIButton *Male;
@property (strong, nonatomic) IBOutlet UIButton *Female;
@end


ViewController.m
#import "ViewController.h"
#import "GSRadioButtonSetController.h"
#import "UICheckbox.h"
@interface ViewController ()

@end
@implementation UIView (FindFirstResponder)
- (UIView *)findFirstResponder
{
    if (self.isFirstResponder) {
        return self;
    }
   
    for (UIView *subView in self.subviews) {
        UIView *firstResponder = [subView findFirstResponder];
       
        if (firstResponder != nil) {
            return firstResponder;
        }
    }
   
    return nil;
}
@end
@implementation ViewController
#pragma mark - GSRadioButtonSetController delegate methods
- (void)viewDidLoad
{
   
    appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
    [self.view addGestureRecognizer:singleTap];
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}


- (void)radioButtonSetController:(GSRadioButtonSetController *)controller didSelectButtonAtIndex:(NSUInteger)selectedIndex
{
    NSString *text = [NSString stringWithFormat:@"%d", selectedIndex];
    NSLog(@"%@",text);
   
}





- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
   
    if ([touch.view isKindOfClass:[UIButton class]]) {              return NO;
    }
    return YES;
}
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    UIView *v =  [keyWindow performSelector:@selector(findFirstResponder)];
    if([v isKindOfClass:[UITextField class]])
    {
        [v resignFirstResponder];
       
    }
   
}
@end

Output Screens


Download Complete Source Code

0 comments:

Post a Comment