2014-12-03 31 views
0

我已經使用以下代碼創建了應用程序。其中當我按下按鈕日期選擇器應加載在相應的行。但日期選擇器總是在第一行中加載。任何人都可以幫助我做到這一點?桌面視圖內部視圖的來源在ios中顯示錯誤的框架

我的代碼如下:提前

- (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]; 
} 

感謝。

+0

你的兩個日誌顯示什麼? – rdelmar 2014-12-03 06:43:24

+1

試試這個'pickerRect.origin.y = rootViewPoint.y'和檢查 – Akhilrajtr 2014-12-03 06:43:50

+0

@rdelmar - 8我的日誌顯示x原點和y原點爲18和日期選擇器顯示只有第一個單元格,但我想我所選單元格 – 2014-12-03 07:53:33

回答

1

該問題可能是由於y的位置爲pickerRect

試試這個

CGRect pickerRect = CGRectMake(cell.actionCardReminder.frame.origin.x, rootViewPoint.y, 304, 204); 

在你的代碼cell.actionCardReminder.framecell內部框架。所以y的位置也將是cell框內的一個點。所以它會始終顯示在第一行。更新y將解決此問題。