Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在Swift中向UIAlertController(UIAlertView)添加日期选择器?_Ios_Swift_Ios8 - Fatal编程技术网

Ios 如何在Swift中向UIAlertController(UIAlertView)添加日期选择器?

Ios 如何在Swift中向UIAlertController(UIAlertView)添加日期选择器?,ios,swift,ios8,Ios,Swift,Ios8,我有一个应用程序,我需要显示一个弹出窗口来选择一个日期并将该日期写回视图控制器 我在网上搜索了很多,但没有找到相关的解决方案 非常感谢您提供的任何帮助。请勿使用任何类型的UIAlertView或UIAlertController。创建自己的视图并将其弹出(可能使用显示的视图控制器)。视图可以很小,比如日期选择器,也可以像警报一样在其后面放置阴影视图。这是我的代码: - (id)initWithDatePicker:(NSString*)title parentView:(UIView*)pare

我有一个应用程序,我需要显示一个弹出窗口来选择一个日期并将该日期写回视图控制器

我在网上搜索了很多,但没有找到相关的解决方案


非常感谢您提供的任何帮助。

请勿使用任何类型的UIAlertView或UIAlertController。创建自己的视图并将其弹出(可能使用显示的视图控制器)。视图可以很小,比如日期选择器,也可以像警报一样在其后面放置阴影视图。

这是我的代码:

- (id)initWithDatePicker:(NSString*)title parentView:(UIView*)parentView {
 self = [super init];

 if (self) {
     datePickerView = [[UIDatePicker alloc] init];
     datePickerView.datePickerMode = UIDatePickerModeDateAndTime;
     if (IS_IOS8_AND_UP) {
         alertViewController = [UIAlertController
                                alertControllerWithTitle:EMPTY_STRING
                                message:title
                                preferredStyle:UIAlertControllerStyleActionSheet];
         UIView* aboveBlurLayer = alertViewController.view.subviews[0];
         [aboveBlurLayer addSubview:datePickerView];
         [aboveBlurLayer setWidth:SCREEN_WIDTH - 16];
         [datePickerView setWidth:SCREEN_WIDTH - 16];
         [alertViewController.view setWidth:SCREEN_WIDTH - 16];
         [alertViewController.view setBackgroundColor:[UIColor whiteColor]];

         UIAlertAction* alertAction =
         [UIAlertAction actionWithTitle:EMPTY_STRING
                                  style:UIAlertActionStyleDefault
                                handler:nil];
         [alertViewController addAction:alertAction];
         [alertViewController addAction:alertAction];
         [alertViewController addAction:alertAction];
         [alertViewController addAction:alertAction];

         [datePickerView setBackgroundColor:[UIColor whiteColor]];
         [aboveBlurLayer addSubview:datePickerView];
     } else {
         actionSheet = [[UIActionSheet alloc] initWithTitle:title
                                                   delegate:self
                                          cancelButtonTitle:nil
                                     destructiveButtonTitle:nil
                                          otherButtonTitles:nil];

         [actionSheet addSubview:datePickerView];
     }

     [self addToolBar];
     isDatePicker = YES;
     parent = parentView;
 }   
  return self; 
}
在工具栏上,我有两个按钮“完成”和“取消” 完成后,我通过代表发回所选日期的电话,取消后,我将解散。
此代码适用于iOS 7和iOS 8

UIAlertView
在iOS 8 SDK中已被弃用。你是说一个
UIAlertController
?如果是这样的话,这个问题可能会有所帮助:@JAL是的,我是说UIAlertController。你给出的链接不是关于Swift的(我指的是用户给出的问题答案)。我不知道Objective-C,我是从Swift开始的,所以我很难将代码转换成Swift。这个例子会让你开始:它不涉及日期选择器,但它展示了如何将任何视图转换成看起来和行为像警报的东西。