【问题标题】:UIAlertview not adding UIDatePicker when i click on textfield?当我单击文本字段时,UIAlertview 没有添加 UIDatePicker?
【发布时间】:2013-12-11 12:50:10
【问题描述】:

当我点击文本字段时,UIAlertview 没有添加 UIDatePicker?

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Preferences"
                                                message:@"\n\n\n\n\n\n\n"
                                               delegate:self
                                      cancelButtonTitle:@"Cancel"
                                      otherButtonTitles:@"OK", nil];
    pickerView=[[UIDatePicker alloc]initWithFrame:CGRectMake(0,40,246,150)];
    pickerView.datePickerMode=UIDatePickerModeDate;
    [alert addSubview:pickerView];
    [alert show];
}

【问题讨论】:

  • 它只显示警报视图而不是警报视图中的日期选择器

标签: iphone ios7 uialertview uidatepicker sdcalertview


【解决方案1】:

iOS 7 不再支持向其层次结构添加子视图。这就是我写SDCAlertView 的原因。它添加了一个 contentView 属性,您可以使用该属性将任何其他视图添加到警报中。

【讨论】:

    【解决方案2】:

    在 iOS7 中 UIAlertView's 视图层次结构已更改,因此现在您无法将任何视图添加到 UIAleartView

    【讨论】:

    • 您可以创建自定义的 Aleartview 或搜索自定义的 aleartview
    【解决方案3】:

    从 iOS7 开始,不再支持向 UIAlertView 添加子视图。您可以使用第三方视图,例如:https://github.com/wimagguc/ios-custom-alertview

    【讨论】:

      【解决方案4】:

      试试这个代码

      UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Hello"
           message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Stamp", nil];
          UIDatePicker  *pickerView=[[UIDatePicker alloc]initWithFrame:CGRectMake(0,40,246,150)];
          pickerView.datePickerMode=UIDatePickerModeDate;
           myAlertView.tag=101;
           [myAlertView show];
          UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(10, myAlertView.bounds.size.height, 320, 216)];
          // Add picker to alert
          [myAlertView addSubview:picker];
          // Adjust the alerts bounds
          myAlertView.bounds = CGRectMake(0, 0, 320 + 20, myAlertView.bounds.size.height + 216 + 20);
           [myAlertView release];
      

      【讨论】:

      【解决方案5】:

      不幸的是,Apple 不允许您添加子视图或修改视图层次结构。请参阅https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html 了解:

      UIAlertView 类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。

      请参阅https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UIAlertView.html#//apple_ref/doc/uid/TP40012857-UIAlertView

      警报视图的外观

      您无法自定义警报视图的外观。

      违反这些规定会导致您的应用在 Apple 审核流程中被拒绝 - 所以我会回去查看您的应用设计。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-30
        • 2015-10-18
        • 1970-01-01
        • 2016-01-25
        • 2013-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多