0

我有以下问题。我想从一个视图转到另一个视图,不是使用按钮,而是编写代码。我有一个视图,其中有一些按钮。当我按下其中一个时,运行 if - else。从其他地方我想去另一个观点。

我试过这个

GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:@"GameOverViewController" bundle:nil];

[self.view removeFromSuperview];
gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];

这个

GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:@"GameOverViewController" bundle:nil];

[self.view removeFromSuperview];
[self.view insertSubview:gOver.view atIndex:0];

和这个

GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:@"GameOverViewController" bundle:nil];

[self.view removeFromSuperview];
[self.view addSubview:gOver.view];

但没有任何效果。有任何想法吗 ?

我也试过这个

GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:@"GameOverViewController" bundle:nil];

[self.view setHidden:YES];
[self.navigationController pushViewController:gOver animated:NO];

抛出异常

[self presentModalViewController:gOver animated:YES];

[self.view insertSubview:gOver.view atIndex:0];

[self.view addSubview:gOver.view];

提前致谢

4

2 回答 2

1

不要调用[self.view removeFromSuperview];这可能会导致您的 viewController 被释放,当使用presentModalViewController它覆盖您的视图时:

GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:@"GameOverViewController" bundle:nil];

// gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];

如果您需要隐藏当前视图,请使用:[self.view setHidden: YES];

于 2012-07-23T14:11:28.820 回答
0

“我想从一个视图转到另一个视图,不是通过按钮,而是编写代码。” - 你是指这个推入故事板还是你的意思是你不希望它出现在按钮动作中?

上面的代码工作正常:

-(IBAction)buttonAction:(id)sender
{
GameViewController *game = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
game.modalTransitionStyle = UIModalTransitionStylePartialCurl ;
[self presentModalViewController:game animated:YES];
}

并希望你做 n iPhone 应用程序而不是 iPad 应用程序,在这种情况下你需要使用 popOver 而不是 modalView

于 2012-07-23T14:52:58.297 回答