来自另一个视图控制器时的 xcode 问题 [英] xcode issues when coming from another view controller

查看:31
本文介绍了来自另一个视图控制器时的 xcode 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 iPhone 应用程序,但遇到了一些问题.我有一个主视图控制器和另一个名为 GameViewController 的控制器.我在主视图控制器中有一个按钮可以进入游戏,在游戏中有一个返回按钮可以返回到主视图控制器.如果我转到游戏视图控制器并返回主界面,下次我按下按钮转到游戏视图控制器时,我会发现各种故障.这是我用于转到 gameViewController 的按钮的代码:

I am developing an iPhone app and have encountered some issues. I have a main view controller and another one called GameViewController. I have a button in the main view controller to go to the game and a back button in the game to go back to the main view controller. If I go to the game view controller and back to the main, the next time I press the button to go to the gameviewcontroller I find all kinds of glitches. Here is my code for the button to go to the gameViewController:

   GameViewController *game = [[GameViewController alloc] initWithNibName:nil bundle:Nil];
    [self dismissViewControllerAnimated:YES completion:NULL];

[self presentViewController:game animated:YES completion:NULL];

这是转到主视图控制器的后退按钮代码:

Here is the back button code to go to the main view controller:

    ViewController *home = [[ViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *parentViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^
 {
     [parentViewController presentViewController:home animated:NO completion:nil];
 }];

如果有人可以提供帮助,将不胜感激.

If anyone can help it would be greatly appreciated.

推荐答案

您返回"的代码并不是真正返回,而是返回然后呈现主视图控制器的新副本.

You 'back' code isn't really going back, it's going back and then presenting a new copy of the home view controller.

然后,您的游戏"代码正在解除,这将删除当前控制器(因为您在返回时展示了它),然后从中展示游戏.

Then, your 'game' code is dismissing, which will remove the current controller (because you presented it when you went back), and then present the game from it.

这很混乱,因为您将展示其展示控制器已被销毁的控制器.最好使用导航控制器.但是,如果您只是提出和取消,您可以更正当前的代码:

This is messy as you will have presented controllers whose presenting controllers have been destroyed. You would be better off using a navigation controller. But, you can correct your current code if you just present and dismiss like:

家 -> 游戏:

GameViewController *game = [[GameViewController alloc] initWithNibName:nil bundle:Nil];
[self presentViewController:game animated:YES completion:NULL];

游戏 -> 家

[self dismissViewControllerAnimated:YES completion:NULL];

这篇关于来自另一个视图控制器时的 xcode 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆