0

I implemented the accepted answer from here How to display activity indicator in center of UIAlertController?

But it doesn't work, all that is displayed is the title "Creating New User" and no activity indicator is displayed. While running in the debugger I noticed that with the posted code indicator by default has its visibility set to false, so I explicitly added a line to set it to true, but it made no difference. Here then is the code from the accepted answer, with that additional line added. Why is the activity indicator not displayed?

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
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • 1
    `UIAlertController` doesn't support adding subviews. From the docs for `UIAlertController`: *"The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified."* – rmaddy Jun 23 '17 at 16:40
  • 1
    @rmaddy So is that a recent restriction and all the past questions with answers on this topic are out of date? – Gruntcakes Jun 23 '17 at 16:42
  • That has always been there. But people have ignored it many times. Sometimes it works, sometimes it doesn't. But it has never been supported. And something that worked once could easily stop working on the next iOS update. – rmaddy Jun 23 '17 at 16:44
  • When Apple's docs say "... and must not be modified" you ignore that at your own peril. That means what you are doing is not part of the public contract, and is subject to change without warning. – Duncan C Jun 23 '17 at 16:45

0 Answers0