【问题标题】:actionSheet:didDismissWithButtonIndex: is deprecated in iOS 8.3. What is the new method I have to use now?actionSheet:didDismissWithButtonIndex: 在 iOS 8.3 中已弃用。我现在必须使用的新方法是什么?
【发布时间】:2017-06-04 03:25:00
【问题描述】:

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

 [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:

非常感谢。

【问题讨论】:

  • ⌘-点击UIActionSheet。在那里你会找到如何更换它的建议。

标签: ios objective-c xcode uiactionsheet dismiss


【解决方案1】:

您可以使用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

谢谢。

【讨论】:

    【解决方案2】:

    来自苹果的website,明确说你应该使用UIAlertController

    【讨论】:

      猜你喜欢
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 1970-01-01
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      相关资源
      最近更新 更多