Reputation: 1751
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.
Upvotes: 0
Views: 527
Reputation: 5182
The issue may due to y
position of pickerRect
.
Try this
CGRect pickerRect = CGRectMake(cell.actionCardReminder.frame.origin.x, rootViewPoint.y, 304, 204);
In your code cell.actionCardReminder.frame
refer to the frame inside the cell
. So the y
position will also be a point inside cell
frame. So it will always show from first row. Updating y
will solve the issue.
Upvotes: 1