Swift 如何在TabLVIEW操作的屏幕中间显示iPad上的ActualMeutsActudio?

Swift 如何在TabLVIEW操作的屏幕中间显示iPad上的ActualMeutsActudio?,swift,Swift,我知道以前有人问过这个问题,但我找不到正确的解决办法 我有一个tableView UIContextualAction,它调用alertController。在iPad上,我希望它出现在中央屏幕上。viewStack由一个带有tableViewController的模式化VC组成 这将在tableViewRow显示警报控制器 let configureAction=UIContextualAction(样式:.normal,标题:nil){[weak self](操作、视图、isSuccess)

我知道以前有人问过这个问题,但我找不到正确的解决办法

我有一个tableView UIContextualAction,它调用alertController。在iPad上,我希望它出现在中央屏幕上。viewStack由一个带有tableViewController的模式化VC组成

这将在tableViewRow显示警报控制器

let configureAction=UIContextualAction(样式:.normal,标题:nil){[weak self](操作、视图、isSuccess)在中
让ac=UIAlertController(标题:LocalizedString.titles.chooseInputMethod,消息:LocalizedString.HelpText.chooseInputMethodSerial,首选样式:。操作表)
popoverController.sourceView=view
popoverController.sourceRect=view.bounds
试图将其显示在中央屏幕上

popcovercontroller.sourceView=self?.view
popoverController.sourceRect=CGRect(x:self?.view.bounds.midX,y:self?.view.bounds.midY,宽度:0,高度:0)
错误:传递给不带参数的调用的参数

从前面的文章来看,最后一段代码似乎对许多其他代码都是正确的,但我仍然发现了一个语法错误


我不知道你是如何得到你的
popoverController
,因为你没有在代码中清楚地显示它。 下面是一段对我来说正确的代码:

let ac = UIAlertController(title: "Pop-up", message: "Message", preferredStyle: .actionSheet)
let popoverController = ac.popoverPresentationController
popoverController?.sourceView = self.view
popoverController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
present(ac, animated: true, completion: nil)
关于您得到的错误:

错误:传递给不带参数的调用的参数

  • 我不确定它是否与这个popoverController有关。你能用显示错误的代码行截图吗
编辑

let configureAction = UIContextualAction(style: .normal, title: nil) { [weak self] (action, view, isSuccess) in 
    guard let self = self else { return }

    //...other code that you have

    if let popoverController = ac.popoverPresentationController {
        popoverController.sourceView = self.view
        popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
    }
}
出现该错误的原因很可能是因为
self
较弱,因此,它会为
x
y
参数返回可选值。
我包括了
guard let self=self else{return}
,它将捕获闭包的self,并保留对它的强引用,直到您的闭包完成执行。

我不确定您是如何获得
popoverController
,因为您没有在代码中清楚地显示它。 下面是一段对我来说正确的代码:

let ac = UIAlertController(title: "Pop-up", message: "Message", preferredStyle: .actionSheet)
let popoverController = ac.popoverPresentationController
popoverController?.sourceView = self.view
popoverController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
present(ac, animated: true, completion: nil)
关于您得到的错误:

错误:传递给不带参数的调用的参数

  • 我不确定它是否与这个popoverController有关。你能用显示错误的代码行截图吗
编辑

let configureAction = UIContextualAction(style: .normal, title: nil) { [weak self] (action, view, isSuccess) in 
    guard let self = self else { return }

    //...other code that you have

    if let popoverController = ac.popoverPresentationController {
        popoverController.sourceView = self.view
        popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
    }
}
出现该错误的原因很可能是因为
self
较弱,因此,它会为
x
y
参数返回可选值。
我包括了
guard let self=self-else{return}
,它将捕获闭包的自我并保留对它的强引用,直到您的闭包完成执行。

上传图像:=)@perage是否有效?如果是,请将答案标记为正确。谢谢上传图像:=)@perage是否有效?如果是,请将答案标记为正确。谢谢