UIAlertView 自定义中的 iOS 7 UIDatePicker

问题描述 投票:0回答:5

伙计们,我正在将 UIDatePicker 添加到 UIAlertView 中,就像 this

enter image description here

iOS 6 及以下版本没问题,现在 iOS 7 就这样了

enter image description here

有什么想法为什么会发生这种情况吗?有更好的方法吗?。感谢任何帮助。

ios objective-c ios7 uialertview uidatepicker
5个回答
8
投票

您可以在 iOS7 的标准警报视图中将 accessoryView 更改为任何自己的 customContentView

[alertView setValue:customContentView forKey:@"accessoryView"];

请注意,您必须在

[alertView show]之前调用此方法。

最简单的说明示例:

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil]; UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]; v.backgroundColor = [UIColor yellowColor]; [av setValue:v forKey:@"accessoryView"]; [av show];

enter image description here

以完全相同的方式添加您的

DatePicker


3
投票
这是我在AlertView中支持addSubview的组件。

CXAlertView - 自定义警报视图,允许您添加视图作为主要内容。

enter image description here


3
投票
在 iOS7 上,您应该使用 UIKit 中新的自定义模式转换支持,使用

UIModalPresentationCustom

transitioningDelegate

使用这些,您可以创建一个类似于警报视图的视图,但是是自定义的,您可以在其中添加日期选择器。

更多信息请点击这里:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewControllerTransitioningDelegate_protocol/Reference/Reference.html#//apple_ref/occ/intf/UIViewControllerTransitioningDelegate


3
投票
这个问题没有解决办法。向 UIAlertView 添加子视图从来不被支持,在 iOS 7 中这会导致子视图不显示。 Apple 开发者论坛上已发布了一些解决方法,但它们很容易在未来的版本中出现问题。

我建议提交错误报告。许多其他人(包括我自己)都这样做了,苹果收到的请求越多,它的优先级就越高。

编辑:我编写了一个UIAlertView

克隆,它允许添加子视图:
SDCAlertView


1
投票
它不受支持,我不相信他们“解决这个问题”..推出您自己的警报视图或使用开源替代方案。另请参阅 iOS7 中的

UIAlertView addSubview

© www.soinside.com 2019 - 2024. All rights reserved.