IOS 7 UIDatePicker in setting UIAlertView

Guys I added UIDatePicker to UIAlertView, like this

enter image description here

It was fine with iOS 6 and below now in iOS 7, as it happens

enter image description here

Any ideas why this is happening? Is there a better way to do this? Any help is appreciated.

+2
source share
5 answers

This is my component for supporting addSubview in AlertView.

CXAlertView - A custom alert view that allows you to add a view as the main content.

enter image description here

+3
source

You can change the accessory for any of your own customContentView in the standard warning view in iOS7

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

Note that you must call this before [alertView show].

The simplest illustrative example:

 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

Similarly, you can add your DatePicker.

+8
source

There is no fix for this. Adding subviews to UIAlertView was never supported, and in iOS 7 this led to subviews not showing up. Some workarounds have been posted on Apple Developer Forums, but they can easily break in a future version.

I suggest creating a bug report. Many others (including me) have done this, and the more requests Apple receives, the higher the priority.

EDIT: I wrote a clone of UIAlertView that allows you to add subviews: SDCAlertView .

+3
source

In iOS7, you should use the new custom modal transition support in UIKit with UIModalPresentationCustom and transitioningDelegate .

Using them, you can create a view similar to the warning view, but custom, where you could add a date picker.

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

+3
source

This is not supported, and I do not believe that they "fixed it." Minimize your own warning or use the open source alternative. see also UIAlertView addSubview in iOS7

+1
source

All Articles