我看过很多主题,其中多个 ViewController 转到一个 ViewController,但不是相反。
我正在制作一个游戏,您可以从 Game_select.m 中选择一个游戏,它需要发送到 6 个 View Controller 之一。我试过使用 Storyboard并对其进行硬编码,但对我来说都没有用。
我已经将 Game1.h 和 Game2.h 导入到 Game_select.m 中。 当我运行我的代码时,它总是转到 Game1 ViewController。 这是我正在尝试的代码:
if(getGame1) {
//go to game1
Game1 *game1 = [[Game1 alloc] init];
[self.navigationController pushViewController:game1 animated:YES];
}
if(getGame2) {
//go to game2
Game2 *game2 = [[Game2 alloc] init];
[self.navigationController pushViewController:game2 animated:YES];
}
感谢您的帮助。 干杯。
最佳答案
我个人不会在这种情况下使用导航 Controller 。使您的所有 viewControllers 成为(正常的)UIViewController
的子类,然后使用此代码呈现您的 viewControllers 之一:
请注意,此代码仅在您以编程方式设置 View 或使用 xib(而 Non-Storyboard )时才有效,如果您使用 initWithNibName: bundle:
而不是使用 初始化
if(getGame1) {
//go to game1
Game1 *game1 = [[Game1 alloc] init];
[self presentViewController:game1 animated:YES completion:nil];
}
if(getGame2) {
//go to game2
Game2 *game2 = [[Game2 alloc] init];
[self presentViewController:game2 animated:YES completion:nil];
}
关于iphone - XCode:单个 ViewController 转到多个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16006545/