但我一直在尝试在界面生成器中完成它,我已经创建了一个名为DatePickerVIEwController.m的视图控制器,其中包含一个DatePicker及其相应的IBoulet
#import <UIKit/UIKit.h>@interface DatePickerVIEwController : UIVIEwController@property (strong,nonatomic) IBOutlet UIDatePicker *birthdayDatePicker;@end
然后,当编辑生日文本字段时,我需要在d出框中显示它.所以我使用以下代码
- (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)}
我还在当前的VIEwController中导入自定义DatePickerVIEwController
#import "DatePickerVIEwController.h"
但它没有在popover中显示datepicker.
有人知道会发生什么吗?
解决方法 您可能希望通过以编程方式创建VIEwController和DatePicker来避免故事板中的所有工作://build our custom popover vIEwUIVIEw *v = [[UIVIEw alloc] init];CGRect pickerFrame = CGRectMake(0,320,216);UIDatePicker *pVIEw=[[UIDatePicker alloc] initWithFrame:pickerFrame];pVIEw.datePickerMode = UIDatePickerModeDate;self.datePicker = pVIEw;[v addSubvIEw:self.datePicker];UIVIEwController *popoverContent = [[UIVIEwController alloc]init];popoverContent.vIEw = v;//resize the popover vIEw shown//in the current vIEw to the vIEw's sizepopoverContent.contentSizeforVIEwInPopover = CGSizeMake(320,216);// dismiss existing popoverif (self.pcdatePicker){ [self.pcdatePicker dismisspopoverAnimated:NO]; self.pcdatePicker = nil;}//create a popover controller with my DatePickerVIEwController in itUIPopoverController *popoverControllerForDate = [[UIPopoverController alloc] initWithContentVIEwController:popoverContent];//Set the delegate to self to receive the data of the Datepicker in the popoverpopoverControllerForDate.delegate = self;//Adjust the popover Frame to appear where I wantCGRect myFrame = sender.frame;//CGRectMake(SCREEN_WIDTH / 2,SCREEN_HEIGHT / 2,200);myFrame.origin.x = 260;myFrame.origin.y = 320;//Present the popover[popoverControllerForDate presentPopoverFromrect:myFrame inVIEw:self.vIEw permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];self.pcdatePicker = popoverControllerForDate;
然后使用委托方法获取日期:
- (voID)popoverControllerDIDdismisspopover:(UIPopoverController *)popoverController{ self.startDate = self.datePicker.date;}总结
以上是内存溢出为你收集整理的ios – 如何使用StoryBoard在iPad上的Popover中显示UIDatePicker?全部内容,希望文章能够帮你解决ios – 如何使用StoryBoard在iPad上的Popover中显示UIDatePicker?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)