UIAlertController does not disappear

I do not understand what is wrong with my code. I just show a warning with the OK button, and when the user clicks OK, then the warning should go. But it did not disappear. Using Swift3 for programming. Is this the viewDidAppear()right place to put this code? Or am I doing something wrong?

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let alertController = UIAlertController(title: "Wrong Item", message: "Could not find details of an item.", preferredStyle: .alert)          
    alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
    present(alertController, animated: true, completion: nil)  
}

UPDATE : When I put the same code in another controller, it worked. In the source controller in viewDidLoad () , I have a call Asyncas shown below. Is this a problem?

DispatchQueue.global(qos: .background).async {
    self.getDetails(onCompletion: {(json: JSON) in

    let dict = self.convertToDictionary(text: json.stringValue)

        DispatchQueue.main.async {

            self.activityIndicator.stopAnimating()
            UIApplication.shared.endIgnoringInteractionEvents()

            //Other UI update operation

        }
    })
}    

I also override viewWillDisappear()and viewWillAppear()to set the screen title.

+6
5

viewDidAppear() , . , Async, viewDidAppear()

self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents()
+1

UIApplication.shared.beginIgnoringInteractionEvents() ? , .

+5

" "

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let alertController = UIAlertController(title: "Wrong Item", message: "Could not find details of an item.", preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        present(alertController, animated: true, completion: nil)
    }

2017-08-15 16: 27: 35.871 test [66719: 7754741] : , !

.

:

   override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let alertController = UIAlertController(title: "Wrong Item", message: "Could not find details of an item.", preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        present(alertController, animated: true, completion: nil)
    }

, .

, , , .

viewDidLoad() viewDidAppear (_:)

beginIgnoringInteractionEvents

viewDidAppear, , , :

viewdidload

        DispatchQueue.main.async {

            self.activityIndicator.stopAnimating()
            UIApplication.shared.endIgnoringInteractionEvents()

            //Other UI update operation

        }

( , ), viewDidAppear , :

DispatchQueue.global(qos:.background).async

?

+1

endIgnoringInteractionEvents() , OK, . .

0

, viewDidAppear , , , . , () Xcode .

, :

  • Xcode Simulator
  • , , .
-2

All Articles