How to present UIAlertController when not in a view controller?

前端 未结 30 3150
庸人自扰
庸人自扰 2020-11-22 06:21

Scenario: The user taps on a button on a view controller. The view controller is the topmost (obviously) in the navigation stack. The tap invokes a utility class method call

30条回答
  •  花落未央
    2020-11-22 06:50

    You can try to implement a category on UIViewController with mehtod like - (void)presentErrorMessage; And and inside that method you implement UIAlertController and then present it on self. Than in your client code you will have something like:

    [myViewController presentErrorMessage];

    In that way you'll avoid unneccessary parametrs and warnings about view not being in window hierarchy.

提交回复
热议问题