actionSheet:didDismissWithButtonIndex:在 iOS 8.3 中已弃用。我现在必须使用的新方法是什么?

actionSheet:didDismissWithButtonIndex: is deprecated in iOS 8.3. What is the new method I have to use now?

这些已被弃用,但我找不到改进它的解决方案:

 [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Take Photo", nil) style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action)
                          {
                              [self actionSheet:nil didDismissWithButtonIndex:0];
                          }]];

并且:

  [[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Take Photo", nil), NSLocalizedString(@"Photo Library", nil), nil] showInView:controller.view];

最后:

- (void)actionSheet:(__unused UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    switch (buttonIndex)
    {
        case 0:
        {
            sourceType = UIImagePickerControllerSourceTypeCamera;
            break;
        }
        case 1:

非常感谢。

来自苹果的website, It is clearly said you should use UIAlertController

您可以使用 UIAlerController,因为 UIActionSheetiOS 8.3 之后被弃用。

请看下面的代码供您参考。

UIAlertController* alert = [UIAlertController
                                alertControllerWithTitle:nil      //  Must be "nil", otherwise a blank title area will appear above our two buttons
                                message:nil
                                preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* button0 = [UIAlertAction
                              actionWithTitle:@"Cancel"
                              style:UIAlertActionStyleCancel
                              handler:^(UIAlertAction * action)
                              {
                                  //  UIAlertController will automatically dismiss the view
                              }];

UIAlertAction* button1 = [UIAlertAction
                              actionWithTitle:@"Camera"
                              style:UIAlertActionStyleDestructive
                              handler:^(UIAlertAction * action)
                              {
//  The user tapped on "Camera"
}];

UIAlertAction* button2 = [UIAlertAction
                              actionWithTitle:@"Photo Library"
                              style:UIAlertActionStyleDestructive
                              handler:^(UIAlertAction * action)
                              {
//  The user tapped on "Camera"
}];

[alert addAction:button0];
[alert addAction:button1];
[alert addAction:button2];
[self presentViewController:alert animated:YES completion:nil];

希望这会指导您进入 UIAlterController 以取代 UIActionSheet

谢谢。