Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
tableview单元格内的视图原点在ios中显示错误的帧_Ios_Objective C_Iphone_Uitableview - Fatal编程技术网

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-实际上它也显示仅第一行中的日期选择器。。