Display Alert Message from viewDidLoad

后端 未结 4 1365
孤街浪徒
孤街浪徒 2021-01-08 01:01

I want to display a alert message from viewDidLoad() method of ViewController.m instead from viewDidAppear() method.

Here is m

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-08 01:16

    OK not a bug, the issue is that in viewDidLoad the view hierarchy is not fully set. If you use viewDidAppear, then the hierarchy is set.

    If you really want to call this alert in viewDidLoad you can do so by wrapping your presentation call in this GCD block to cause a slight delay, waiting for the next run loop, however I suggest you don't (it's ugly).

    dispatch_async(dispatch_get_main_queue(), ^ {
        [self presentViewController:alert animated:YES completion:nil];
    });
    

提交回复
热议问题