具有actionSheet样式的警报显示为带有延迟的标题和消息

问题描述 投票:1回答:2

自iOS 13.1起,我的带actionSheet样式的警报显示为“已延迟”标题和消息。

这些是苹果的release notes

[我已经进行了很多研究,但是找不到如何使其像iOS 13.1之前那样工作的情况,在iOS 13.1之前,标题和消息是在操作按钮的同时呈现的。

这是创建警报并显示警报的方法:

    private func showRemoveConfirmationAlert() {
        let alert = UIAlertController(
            title: "Remove device?".localized(), 
            message: "Are sure you want to remove this device from your account?\nMake sure to unpair your device before removing it. This action cannot be undone.".localized(), 
            preferredStyle: .actionSheet
        )

        alert.addAction(UIAlertAction(title: "Remove".localized(), style: .destructive, handler: { _ in
            AnalyticsHelper.logRemoveDeviceConfirmedTapped()
            self.viewModel?.removeFromAccount()
        }))
        alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { _ in
            AnalyticsHelper.logCancelTapped()
        }))

        if let popoverController = alert.popoverPresentationController {
            popoverController.sourceView = self.view
        }

        self.present(alert, animated: true)
    }

这是它的外观:

Alert being shown with delayed title and message

任何帮助将不胜感激!预先感谢。

ios swift ios13 uialertcontroller presentviewcontroller
2个回答
0
投票

这是iOS 13以后的默认行为。如果要立即渲染,请将动画更改为false

self.present(alert, animated: false, completion : nil)

0
投票

尝试此方式:

  private func showRemoveConfirmationAlert() {
        let alert = UIAlertController(
            title: "Remove device?".localized(), 
            message: "Are sure you want to remove this device from your account?\nMake sure to unpair your device before removing it. This action cannot be undone.".localized(), 
            preferredStyle: .actionSheet
        )

        alert.addAction(UIAlertAction(title: "Remove".localized(), style: .destructive, handler: { _ in
            AnalyticsHelper.logRemoveDeviceConfirmedTapped()
            self.viewModel?.removeFromAccount()
        }))
        alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { _ in
            AnalyticsHelper.logCancelTapped()
        }))

      //  if let popoverController = alert.popoverPresentationController {
      //      popoverController.sourceView = self.view
      //  }

        self.present(alert, animated: true)
    }

我认为此问题可能是由于.localized()造成的

© www.soinside.com 2019 - 2024. All rights reserved.