我有一个iOS6应用程序使用以下代码创建带有时间选择器的UIActionSheet:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
//Configure picker...
[pickerView setMinuteInterval:5];
[pickerView setTag: 4];
[pickerView setDatePickerMode:UIDatePickerModeTime];
//Add picker to action sheet
[actionSheet addSubview:pickerView];
//Gets an array of all of the subviews of our actionSheet
NSArray *subviews = [actionSheet subviews];
[[subviews objectAtIndex:1] setFrame:CGRectMake(20, 266, 280, 46)];
[[subviews objectAtIndex:2] setFrame:CGRectMake(20, 317, 280, 46)];
}
在iOS7中尝试它之前它就像一个魅力,当我点击弹出动作表的输入字段时,它总是崩溃。以下是输入字段背后的代码:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
selectedTag = textField.tag;
// the input field that needs to show the actionsheet has tag 1.
if (selectedTag == 1) {
UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Select a time:"
delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Select", nil];
[asheet showInView:[self.view superview]];
[asheet setFrame:CGRectMake(0, 110, 320, 500)];
textField.userInteractionEnabled = NO;
}
textField.userInteractionEnabled = YES;
}
当应用程序崩溃时,我收到以下消息:
答案 0 :(得分:5)
如果您希望在单击文本字段时显示日期选择器,则可以直接显示日期选择器。将日期选择器作为文本字段的输入视图。
pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
//Configure picker...
[pickerView setMinuteInterval:5];
[pickerView setDatePickerMode:UIDatePickerModeTime];
[dateTextField setInputView:pickerView];
答案 1 :(得分:0)
试试这个..
[asheet showInView:self.view];