Как закрыть UIActionSheet кнопкой закрытия и избежать краха?

Я прочитал в другом сообщении (how to dismiss action sheet), что я могу использовать

[actionSheet dismissWithClickedButtonIndex:0 animated:YES];

to dismiss the uiactionsheet with the close button, as defined in:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                                         delegate:nil
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 40, 0, 0);

UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;


[actionSheet addSubview:pickerView];
[pickerView release];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];


[actionSheet dismissWithClickedButtonIndex:0 animated:YES];


[closeButton release];


[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];

[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

Однако я не уверен, где разместить эту строку, предполагая, что это решит мою проблему:

[actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 

Также, приложение падает, когда я нажимаю кнопку закрытия, с сообщением об ошибке "PROGRAM RECEIVED ERROR MESSAGE SIGBRT". Я предполагаю, что мои две проблемы связаны. Помогите, пожалуйста.

6
задан Community 23 May 2017 в 11:44
поделиться