tableview单元格内的视图原点在ios中显示错误的帧
我用以下代码创建了应用程序。其中,当我按下按钮时,日期选择器应加载到相应的行中。但是日期选择器总是在第一行加载。有人能帮我做这件事吗 我的代码如下:tableview单元格内的视图原点在ios中显示错误的帧,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,我用以下代码创建了应用程序。其中,当我按下按钮时,日期选择器应加载到相应的行中。但是日期选择器总是在第一行加载。有人能帮我做这件事吗 我的代码如下: - (void)datePickerButtonPressed:(UIButton *)sender { if(self.datePicker == nil) { self.datePicker = [[UIDatePicker alloc] init]; [self.datePicker addTarget:self action
- (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];
}
提前感谢。问题可能是由于
pickerRect
的y
位置造成的
试试这个
CGRect pickerRect = CGRectMake(cell.actionCardReminder.frame.origin.x, rootViewPoint.y, 304, 204);
在您的代码
单元格中。actionCardReminder.frame
参考单元格中的框架。因此y
位置也将是单元
帧内的一个点。所以它总是从第一排开始显示。更新y
将解决此问题。您的两个日志显示了什么?请尝试此pickerRect.origin.y=rootViewPoint.y
并check@rdelmar-我的日志在8处显示x原点,在18处显示y原点,datepicker仅在第一个单元格显示,但我希望所选单元格的原点相同您可以检查一次:@Akhilrajtr-实际上它也显示仅第一行中的日期选择器。。