I am building an iOS app.I am using storyboards to build the screens and i have made a form which contain some fields like Name,Date,min and max.
I am facing an problem
-(IBAction)datePickerBtnAction:(id)sender
{
datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0,10, 50)];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.hidden = NO;
datePicker.date = [NSDate date];
[datePicker addTarget:self action:@selector(labelTitle:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];
rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(save:)];
self.navigationItem.rightBarButtonItem = rightBtn;
}
-(void)labelTitle:(id)sender
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
dateFormat.dateStyle = NSDateFormatterMediumStyle;
[dateFormat setDateFormat:@"MM/dd/yyyy"];
NSString *str = [NSString stringWithFormat:@"%@",[dateFormat stringFromDate:datePicker.date]];
//assign text to label
label.text=str;
}
-(void)save:(id)sender
{
self.navigationItem.rightBarButtonItem = nil;
[datePicker removeFromSuperview];
}