Attempt to present * on * whose view is not in the window hierarchy

前端 未结 7 1212
半阙折子戏
半阙折子戏 2020-11-30 05:29

I\'m trying to make a modal view controller in my app delegate (I created a function called showLoginView). But whenever I try to call it I get a warning in XCode:



        
7条回答
  •  时光取名叫无心
    2020-11-30 06:05

    Faced this issue while trying to present controller from the call of delegate of other controller . i.e : show search filter with delegate , once done back to my controller and receive data via the delegate then present controller , all I had to do is to dispatch the present code cause while in a delegate you're in another thread , that's why you're presenting on your view from main thread another controller from that other thread , so have to go back to main thread , just put the presenting code like this :

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

    Hope this helps !

提交回复
热议问题