简体   繁体   English

tableview单元格内的视图原点在ios中显示错误的框架

[英]origin of view inside the tableview cell shows wrong frame in ios

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. 但是datepicker总是在第一行中加载。 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. 提前致谢。

The issue may due to y position of pickerRect . 问题可能是由于pickerRect y位置。

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 . 在您的代码cell.actionCardReminder.frame引用cell内的框架。 So the y position will also be a point inside cell frame. 因此, y位置也将是cell框架内的一个点。 So it will always show from first row. 因此它将始终从第一行显示。 Updating y will solve the issue. 更新y将解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM