I guess the answer is easy but I've been days trying to solve the problem and can not find the solution. This is a UIViewController after certain checks and without using any button, display a UIAlertController. Always appear Warning: Attempt to present on whose view is not in the window hierarchy!
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
noData()
}
func noData(){
let alertController = UIAlertController(title: "Message", message: "There area no data in the file" , preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}