使用StoryBoard在iPad上的Popover显示UIDatePicker
问题说明
我已经实现了在popover中显示日期选择器,按照中的显示进行编程UIPopover中的UIDatePicker 。
I have achieved to show the datepicker inside the popover, doing it programmatically as it is shown in UIDatePicker in UIPopover.
但我一直在尝试在界面生成器中执行此操作,我已经创建了一个名为DatePickerViewController.m的视图控制器,其中包含一个DatePicker及其相应的IBoulet
But I have been trying to do it in interface Builder, I already made a View Controller named DatePickerViewController.m with a DatePicker in it and its corresponding IBoulet
#import <UIKit/UIKit.h>
@interface DatePickerViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIDatePicker *birthdayDatePicker;
@end
然后我需要这个在生日时弹出窗口正在编辑文本字段。所以我使用以下代码
Then I need this to be shown in a popover when the Birthday text field is being edited. so I use the following code
- (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
And I also import the custom DatePickerViewController in my current ViewController
#import "DatePickerViewController.h"
但它没有在popover中显示datepicker。
But it is not showing the datepicker inside the popover.
有人知道会发生什么吗?
Does anybody know what could be happening?
正确答案
解决了
我所要做的就是将StoryBoard日期选择器视图控制器实例化为:
All I have to do is instantiate the StoryBoard Date Picker View Controller like :
...
DatePickerViewController* popoverContent = [[DatePickerViewController alloc] init];
popoverContent =[[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:nil]
instantiateViewControllerWithIdentifier:@"DatePickerVC"];
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 216);
...
其中标识符在StoryBoard属性检查器中设置
where the identifier is set in StoryBoard Attributes Inspector
现在显示
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfiafc
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20