これは古い質問であることは知っていますが、以下はOPが要求したものを許可すると信じており、AlertView階層の変更に関するAppleの規則に違反するとは思いません:
- (void)requestDateOfBirth
{
UIDatePicker *birthDatePicker;
UIAlertView *setBirthDate;
NSDateFormatter *birthDateFormatter;
UITextField *birthDateInput;
//create the alertview
setBirthDate = [[UIAlertView alloc] initWithTitle:@"Date of Birth:"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
setBirthDate.alertViewStyle = UIAlertViewStylePlainTextInput;
//create the datepicker
birthDatePicker = [[UIDatePicker alloc] init];
[birthDatePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
birthDatePicker.datePickerMode = UIDatePickerModeDate;
birthDatePicker.date = [NSDate date];
//get the textfield provided in the plain text alertview
birthDateInput = [setBirthDate textFieldAtIndex:0];
//change the textfields inputView to the date picker
birthDateInput.inputView = birthDatePicker;
[birthDateInput setTextAlignment:NSTextAlignmentCenter];
//create a date formatter to suitably show the date
birthDateFormatter = [[NSDateFormatter alloc] init];
[birthDateFormatter setDateStyle:NSDateFormatterShortStyle];
//set the current date into the textfield
birthDateInput.text = [birthDateFormatter stringFromDate:[NSDate date]];
//show the alert view and activate the textfield
[setBirthDate show];
[birthDateInput becomeFirstResponder];
}
次に、日付ピッカーの変更を処理することを忘れないでください
- (void) dateChanged:(id)sender
{
NSDateFormatter *birthDateFormatter;
UIDatePicker *birthDatePicker = (UIDatePicker *)sender;
birthDateFormatter = [[NSDateFormatter alloc] init];
[birthDateFormatter setDateStyle:NSDateFormatterShortStyle];
birthDateInput.text = [birthDateFormatter stringFromDate:birthDatePicker.date];
}
これが役立つことを願っています