我有CalenderVC,它由名为PickerController的Container View组成。 PickerController包含一个工具栏,datepicker.Everytime我想添加日期我使用PickerController但是 我的问题是在某些条件下我也想设置最小日期。我也使用customdelegate传递minimumdate但仍然没有设置最小日期。
//CalendarVC added PickerController
- (void)displayContentView
{
UIStoryboard *story=[UIStoryboard storyboardWithName:@"Pagebar" bundle:nil];
objContent=[story instantiateViewControllerWithIdentifier:@"pickerVCID"];
objContent.datePicker.hidden=false;
self.dtDelegate=objContent;
objContent.view.frame=CGRectMake(0,0, self.view.frame.size.width, 280);
if(isFromDate==false)
{
// delegate method that set minimum date of picker
[self.dtDelegate setMinDate:minimumDate];
}
_pickerContainerVw.hidden=false;
[self addChildViewController:objContent];
[self.view addSubview:_pickerContainerVw];
[objContent didMoveToParentViewController:self];
}
-(void)removeContentView
{
_pickerContainerVw.hidden=true;
[objContent willMoveToParentViewController:nil];
[objContent.view removeFromSuperview];
[objContent removeFromParentViewController];
objContent.view.hidden=true;
}
// In pickercontroller
-(void)setMinDate:(NSDate *)minDate
{
[self.datePicker setMinimumDate:minDate];
[self.view addSubview:self.datePicker];
NSLog(@"minimum date %@",minDate);
}
答案 0 :(得分:0)
您的代码存在一些潜在问题。
datePicker
。 setMinDate:
的视图选择器控制器中?由于您似乎已将其设计为故事板视图控制器,因此您已将其作为正确视图中的子项使用。在这种情况下,你可以隐藏/显示它。_pickerContainerVw
?它与objContent.view
相同吗?您正在将objContent
添加为子视图控制器,但将_pickerContainervW
添加为子视图。您可能希望将objContent.view
添加为子视图。由于我没有看到您的所有代码,因此存在因我的更改而引入副作用的风险,我已经解决了上述问题。
//CalendarVC added PickerController
- (void)displayContentView
{
// Instantiate picker
UIStoryboard *story=[UIStoryboard storyboardWithName:@"Pagebar" bundle:nil];
objContent=[story instantiateViewControllerWithIdentifier:@"pickerVCID"];
self.dtDelegate=objContent;
objContent.view.frame=CGRectMake(0,0, self.view.frame.size.width, 280);
// Add it as a child VC
[self addChildViewController:objContent];
[self.view addSubview:objContent.view];
[objContent didMoveToParentViewController:self];
// Start with hidden date picker, show if needed
objContent.datePicker.hidden = YES;
if(isFromDate==false)
{
// delegate method that set minimum date of picker
objContent.datePicker.hidden = NO;
[self.dtDelegate setMinDate:minimumDate];
}
}
-(void)removeContentView
{
[objContent willMoveToParentViewController:nil];
[objContent.view removeFromSuperview];
[objContent removeFromParentViewController];
}
// In pickercontroller
-(void)setMinDate:(NSDate *)minDate
{
[self.datePicker setMinimumDate:minDate];
NSLog(@"minimum date %@",minDate);
}