I have created the app with the following code. In which when i press the button the date picker should load in corresponding row. But the datepicker is always loading in the first row. Can anyone help me to do this?
My code as follows:
- (void)datePickerButtonPressed:(UIButton *)sender
{
if(self.datePicker == nil)
{
self.datePicker = [[UIDatePicker alloc] init];
[self.datePicker addTarget:self action:@selector(datePickerDateChanged:) forControlEvents:UIControlEventValueChanged];
}
NSMutableArray *items = [self.toolbar.items mutableCopy];
[items removeObjectAtIndex:2];
[items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(datePickerDone:)]];
[self.toolbar setItems:items animated:YES];
CGPoint swipepoint = sender.center;
CGPoint rootViewPoint = [sender.superview convertPoint:swipepoint toView:self.goalDetailsTableview];
NSIndexPath *indexPath = [self.goalDetailsTableview indexPathForRowAtPoint:rootViewPoint];
NSLog(@"%@", indexPath);
GoalDetailsTableViewCell *cell = [self.goalDetailsTableview cellForRowAtIndexPath:indexPath];
self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
CGRect pickerRect = CGRectMake(cell.actionCardReminder.frame.origin.x, cell.actionCardReminder.frame.origin.y, 304, 204);
NSLog(@"%f %f", cell.actionCardReminder.frame.origin.x, cell.actionCardReminder.frame.origin.y);
self.datePicker.frame = pickerRect;
self.datePicker.backgroundColor = [UIColor whiteColor];
self.datePicker.layer.cornerRadius = 5;
[self.goalDetailsTableview addSubview:self.datePicker];
}
Thanks in advance.