Warning: Attempt to present * on * whose view is not in the window hierarchy - swift

前端 未结 17 997
花落未央
花落未央 2020-11-30 22:03

I\'m trying to present a ViewController if there is any saved data in the data model. But I get the following error:

Warning: A

17条回答
  •  生来不讨喜
    2020-11-30 22:13

    Rather than finding top view controller, one can use

    viewController.modalPresentationStyle = UIModalPresentationStyle.currentContext
    

    Where viewController is the controller which you want to present This is useful when there are different kinds of views in hierarchy like TabBar, NavBar, though others seems to be correct but more sort of hackish

    The other presentation style can be found on apple doc

提交回复
热议问题