Pregunta

I had an iOS6 app that used the following code to create a UIActionSheet with a Time Picker:

- (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)];
}

It worked like a charm until I tried it in iOS7, it always crashes when I click the input field that pops up the action sheet. Here is the code behind the input field:

- (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;
}

When the app craches, I get the following message:

enter image description here

¿Fue útil?

Solución

If you want a datepicker to be presented while clicking the textfield, you can directly present the datepicker. Make the datepicker as your textfield's inputview.

    pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];

    //Configure picker...
    [pickerView setMinuteInterval:5];
    [pickerView setDatePickerMode:UIDatePickerModeTime];
    [dateTextField setInputView:pickerView];

Otros consejos

Try this..

[asheet showInView:self.view];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top