Warning: Attempt to present on whose view is not in模态跳转问题

时间:2023-03-10 07:23:26
Warning: Attempt to present on whose view is not in模态跳转问题

错误分析:

           controller A present controller B ,前提是A的view要存在,如果不存在,就会报这个错。
解决方法: 
           将原来的present语句由 viewDidLoad方法中移到 viewDidAppear中,问题就可以解决。但是这样的话,画面会闪现一下parentViewController的view,这个问题目前不清楚怎么解决,有待高人指点。
并且viewDidAppear这个方法是每次都进入,和ViewDidLoad只进一次不同,所以无法达到我要的效果。
最终方案:
           摈弃presentModel方法,在viewDidLoad中添加如下语句:
              [self.view addSubview:controllerB.view];

[self addChildViewController:controllerB];

自己添加想要的动画,实现对presentModel方法的模仿。