我已经实现,以显示酥料饼里面的日期选择器,因为它显示在编程做的UIDatePicker在UIPopover 。
但我一直在努力做在Interface Builder中,我已经在它和它对应的IBoulet取得了视图控制器名为DatePickerViewController.m有一个datepicker
#import <UIKit/UIKit.h>
@interface DatePickerViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIDatePicker *birthdayDatePicker;
@end
然后,我需要这一场酥料饼中显示,当生日文本字段进行编辑。 所以我用下面的代码
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//Assign DatePicker to Birthday TextField
//build our custom popover view
DatePickerViewController* popoverContent = [[DatePickerViewController alloc] init];
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 216);
// dismiss existing popover
if (self.popoverControllerBirthday)
{
[self.popoverControllerBirthday dismissPopoverAnimated:NO];
self.popoverControllerBirthday = nil;
}
//create a popover controller with my DatePickerViewController in it
UIPopoverController *popoverControllerForDate = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
//Set the delegate to self to receive the data of the Datepicker in the popover
popoverControllerForDate.delegate = self;
//Adjust the popover Frame to appear where I want
CGRect myFrame =textField.frame;
myFrame.origin.x = 260;
myFrame.origin.y = 320;
//Present the popover
[popoverControllerForDate presentPopoverFromRect:myFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
self.popoverControllerBirthday = popoverControllerForDate;
return NO; // tells the textfield not to start its own editing process (ie show the keyboard)
}
而且我也导入自定义DatePickerViewController在我目前的ViewController
#import "DatePickerViewController.h"
但它没有显示的酥料饼里面的日期选择器。
有谁知道可能会发生?