为了测试和编写代码,我需要重启我的 GameViewController
GameViewController *controller = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
[self presentModalViewController:controller animated:NO];
此方法重新启动 viewController 但所有存储在内存中,因为我的操作/进程正在进行,因为应用程序内存随着每次不重新启动而增加。 我认为这不是正确的方法,并且想知道如何用内存完全覆盖 viewController,删除所有进程并重新开始。
更新
- (IBAction)restartButtonPress {
// GameViewController *controller = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
// [self presentModalViewController:controller animated:NO];
[self.view setNeedsDisplay];
}
最佳答案
调用 [self.view setNeedsDisplay];
用于重新加载您的 View 。也可以使用 [self viewDidLoad]
方法,但这对我们不利,而且我们不会手动调用 viewDidLoad。所以你可以使用 setNeedsDisplay
。
关于ios - 重启 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15585784/