I want to take a date input using uidatepicker. I have changed the input view of my UITextField to a UIDatePicker object. The DatePicker is displaying, no problem. But then I added a UITapGestureRecognizer so that when the user taps outside the date picker, then date picker will hide. Here I am getting an exception. I cannot hide the date picker.
interface file:
@interface ViewController : UIViewController <UITextFieldDelegate>
{
UIDatePicker *anewPicker;
UITapGestureRecognizer *tapGestureRecognizer;
}
@property (weak, nonatomic) IBOutlet UILabel *labelOutlet;
@property (weak, nonatomic) IBOutlet UITextField *startTimeTxtOutlet;
@property (weak, nonatomic) IBOutlet UITextField *endTimeTxtOutlet;
@property UIDatePicker *anewPicker;
@property UITapGestureRecognizer *tapGestureRecognizer;
@end
implementation file:
@implementation ViewController
@synthesize anewPicker;
@synthesize tapGestureRecognizer;
- (void)viewDidLoad
{
[super viewDidLoad];
self.anewPicker = [[UIDatePicker alloc] initWithFrame:[self.view bounds]];
[anewPicker addTarget:self action:@selector(enteredStartDate:) forControlEvents:UIControlEventValueChanged];
self.startTimeTxtOutlet.inputView = self.anewPicker;
self.endTimeTxtOutlet.inputView = self.anewPicker;
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.view action:@selector(dismissDatePicker:)];
self.tapGestureRecognizer.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:self.tapGestureRecognizer];
}
-(void)enteredStartDate:(id)sender
{
NSLog(@"start date %@",[sender date]);
}
-(void)enteredEndDate:(id)sender
{
NSLog(@"end date %@",[sender date]);
}
-(void)dismissDatePicker:(UIGestureRecognizer*)gestureRecognizer
{
//in this function i get the exception
//other functions are ok
NSLog(@"tap");
self.anewPicker.hidden = YES;
}
@end
Exception: unrecognized selector sent to instance
Platform details:
XCode 4.5.2
deployment target: 6.0
base SDK: 6.0