I have got a UIAlertController that I would like to present within a UITableViewController. However when I run the code I get the following error:
Warning: Attempt to present on whose view is not in the window hierarchy!
My code seem to reflect what suggested in this answer. What am I doing wrong?
override func viewDidLoad() {
super.viewDidLoad()
// Check for force touch feature, and add force touch/previewing capability.
if traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: view)
}
else {
// Create an alert to display to the user.
alertController = UIAlertController(title: "3D Touch Not Available", message: "Unsupported device.", preferredStyle: .alert)
self.present(alertController!, animated: false, completion: nil)
}