Ios 向UIAlertController添加活动指示器

Ios 向UIAlertController添加活动指示器,ios,swift,uialertcontroller,Ios,Swift,Uialertcontroller,我从这里实现了公认的答案 但它不起作用,只显示标题“创建新用户”,不显示活动指示器。在调试器中运行时,我注意到,默认情况下,对于发布的代码指示符,其可见性设置为false,因此我显式添加了一行以将其设置为true,但没有任何区别。 下面是已接受答案中的代码,并添加了该行。为什么不显示活动指示器 func displaySignUpPendingAlert() -> UIAlertController { //create an alert controller let pe

我从这里实现了公认的答案

但它不起作用,只显示标题“创建新用户”,不显示活动指示器。在调试器中运行时,我注意到,默认情况下,对于发布的代码指示符,其可见性设置为false,因此我显式添加了一行以将其设置为true,但没有任何区别。 下面是已接受答案中的代码,并添加了该行。为什么不显示活动指示器

func displaySignUpPendingAlert() -> UIAlertController
{
    //create an alert controller
    let pending = UIAlertController(title: "Creating New User", message: nil, preferredStyle: .alert)
    let indicator = UIActivityIndicatorView(frame: pending.view.bounds)
    indicator.autoresizingMask = [.flexibleWidth, .flexibleHeight]

    //add the activity indicator as a subview of the alert controller's view
    pending.view.addSubview(indicator)
    indicator.isUserInteractionEnabled = false // required otherwise if there buttons in the UIAlertController you will not be able to press them
    indicator.isHidden = false
    indicator.startAnimating()
    self.present(pending, animated: true, completion: nil)
    return pending
}

UIAlertController
不支持添加子视图。在
UIAlertController
的文档中:“UIAlertController类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不能修改。”@rmaddy那么,最近的一个限制和过去所有关于这个主题的问题和答案都过时了吗?这一直存在。但人们多次忽视了这一点。有时有效,有时无效。但它从未得到支持。而曾经有效的东西很容易在下一次iOS更新中停止工作。当苹果的文档说“……而且不能修改”时,你忽视了这一点,后果自负。这意味着你所做的不是公共合同的一部分,可能会在没有警告的情况下进行更改。