将UIImageview添加到subView后,无法单击UIAlertView中的按钮

时间:2013-12-16 12:53:25

标签: ios objective-c uiimageview uialertview addsubview

“确定”按钮无效。 我知道这件事发生了,因为我添加了backgroundImageView。 我怎样才能使它发挥作用?

这是我的代码:

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"clock"]];

backgroundImageView.frame = CGRectMake(0, 0, 282, 200);

backgroundImageView.contentMode = UIViewContentModeScaleToFill;
backgroundImageView.userInteractionEnabled = YES;

[alert addSubview:backgroundImageView];

[alert sendSubviewToBack:backgroundImageView];

[alert show];

4 个答案:

答案 0 :(得分:2)

不幸的是,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 Review流程中拒绝您的应用 - 所以我会回过头来看看您的应用设计。

答案 1 :(得分:2)

Apple不允许您将子视图添加到UIAlertView。子类UIAlertView不是一个选项,这个类不打算被子类化,这样做可能是拒绝应用的原因。

您可以使用here中的库来自定义UIAlertView

答案 2 :(得分:1)

不要将子视图添加到UIAlertView,这是不受支持的功能。如果您需要创建自定义视图,请找到支持您需要的第三方警报视图解决方案并改为使用它。

答案 3 :(得分:1)

Apple不建议将子视图添加到UIAlertView您必须创建自己的警报视图。