简体   繁体   English

尝试提出View Controller警告

[英]Attempt to present View Controller Warning

I have the following ViewControllers that present the next ViewController when something is finished: 我有以下ViewControllers,它们在完成某些操作时显示下一个ViewController:

Nr1: My GameViewController checks that the game has finished and call CheckGameFinished: Nr1:我的GameViewController检查游戏是否已完成,并调用CheckGameFinished:

-(void) checkGameFinished {
if ([self.gameModel isGameOver]) {

    double delayTimeInSeconds = 3.5;
    dispatch_time_t popTimeDelay = dispatch_time(DISPATCH_TIME_NOW, delayTimeInSeconds * NSEC_PER_SEC);
    dispatch_after(popTimeDelay, dispatch_get_main_queue(), ^(void){

    [progressBarTimer invalidate];

    level2ViewController *govc = [self.storyboard instantiateViewControllerWithIdentifier:@"level2ViewController"];

    [self.finishAudio play];

    [self presentViewController:govc animated:NO completion:^(){
        [self.gameModel clearGameData];

    }];
          });
}
}

Then level2ViewController appears: 然后出现level2ViewController:

- (void)viewDidLoad {
[super viewDidLoad];

double delayTimeInSeconds = 2;
dispatch_time_t popTimeDelay = dispatch_time(DISPATCH_TIME_NOW, delayTimeInSeconds * NSEC_PER_SEC);
dispatch_after(popTimeDelay, dispatch_get_main_queue(), ^(void){


    GameViewController *gvc = [self.storyboard instantiateViewControllerWithIdentifier:@"gameViewController"];

    [self presentViewController:gvc animated:NO completion:nil];


});

}

and called the next ViewController, and so on. 并调用下一个ViewController,依此类推。

Now I get overtime the following Warnings: 现在,我收到以下警告:

Warning: Attempt to present GameViewController on level2ViewController whose view is not in the window hierarchy! 警告:尝试在视图不在窗口层次结构中的level2ViewController上显示GameViewController!

Don't present a view controller from viewDidLoad , instead call from viewDidAppear: . 不要从viewDidLoad显示视图控制器,而是从viewDidAppear:调用。 Also using dispatch_after like that (assuming you are using it to hopefully make sure the view is on screen and not for gaming purposes) is a very bad practice. 像这样使用dispatch_after (假设您正在使用它来确保视图在屏幕上而不是出于游戏目的)是非常不好的做法。
When the view controller that is being loaded has done being presented (that happens when viewDidAppear: is called) you can present a different one: 当正在加载的视图控制器已经完成呈现时(在调用viewDidAppear:时发生),您可以呈现一个不同的视图控制器:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    GameViewController *gvc = [self.storyboard instantiateViewControllerWithIdentifier:@"gameViewController"];
    [self presentViewController:gvc animated:NO completion:nil];
}

我得到这个当我segue类型是modal ,改变为push固定对我来说

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:在进行过程中尝试在视图控制器上显示模式控制器 - Warning: Attempt to present modal controller on view controller while in progress 警告:尝试显示*其视图不在窗口层次结构中的对象 - Warning: Attempt to present * whose view is not in the window hierarchy 警告:尝试显示其视图不在窗口层次结构中 - warning: attempt to present whose view is not in the window hierarchy 警告:尝试呈现其视图不在窗口层次结构中的视图 - Warning: Attempt to present on whose view is not in the window hierarchy 警告:尝试在已经呈现的 * 上呈现视图控制器<UISearchController: 0x142a1f7c0> - Warning: Attempt to present View Controller on * which is already presenting <UISearchController: 0x142a1f7c0> 尝试展示另一个类的视图控制器 - Attempt to present a view controller from another class 尝试显示其视图不在层次结构中的控制器 - Attempt to present controller whose view is not in the hierarchy 尝试显示其视图不在窗口层次结构中的控制器 - Attempt to present controller whose view is not in the window hierarchy 警告:试图出席 - warning: attempt to present 警告:尝试在视图不在窗口层次结构中的UINavigationController上显示LastViewController - Warning: Attempt to present LastViewController on UINavigationController whose view is not in the window hierarchy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM