I'm trying to present a ViewController
if there is any saved data in the data model. But I get the following error:
Warning: Attempt to present * on *whose view is not in the window hierarchy"
Relevant code:
override func viewDidLoad() { super.viewDidLoad() loginButton.backgroundColor = UIColor.orangeColor() var request = NSFetchRequest(entityName: "UserData") request.returnsObjectsAsFaults = false var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate) var context:NSManagedObjectContext = appDel.managedObjectContext! var results:NSArray = context.executeFetchRequest(request, error: nil)! if(results.count <= 0){ print("Inga resultat") } else { print("SWITCH VIEW PLOX") let internVC = self.storyboard?.instantiateViewControllerWithIdentifier("internVC") as internViewController self.presentViewController(internVC, animated: true, completion: nil) } }
I've tried different solutions found using Google without success.
At this point in your code the view controller's view has only been created but not added to any view hierarchy. If you want to present from that view controller as soon as possible you should do it in viewDidAppear
to be safest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With