从一个视图移动到另一个iOS

时间:2013-01-11 00:48:33

标签: ios objective-c ipad

我对iOS开发相对较新。我要从一个viewController移动到另一个viewController,我在按钮点击时使用模态segue转换。这是一款游戏,所以我想让用户点击图片来移动应用菜单。

我有一个显示多个图像的主页面,点击一个我希望能够移动到另一个视图的图像。目前使用模态segue执行此操作会导致我的touchesEnded事件出现奇怪问题,例如,如果我导航到页面3次,则touchesEnded事件会被触发3次。

我有更好的方法来做这件事,还是我只是缺少基本的东西?

由于

3 个答案:

答案 0 :(得分:1)

我假设您正在使用Storyboard使用segue链接VC。

模态segue非常适合简单的过渡,但实际上似乎限制了当它们通过SB链接时可以完成的任务。我发现创建一个包含以下VC segue的IBAction,不仅可以让您更有效地控制segue,还可以让您更清楚地了解转换过程中实际发生的情况。

-(IBAction)goToVc:(id)sender{
    //Other code to take place during the segue here

    //This will identify the Storyboard in use
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard"   bundle:nil];

    //This will identify the View Controller to switch to
    SecondViewController *vc2 = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewControllerID" ];

    [self presentViewController:vc2 animated:YES completion:NULL];
}

答案 1 :(得分:1)

是的,我认为您必须使导航控制器成为根视图控制器,然后相应地推送视图

UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:YOUR_BASE_CONTROLLER]
self.rootViewController = nav;

这是在您的app委托中。

然后在你的行动方法

[self.navigationController pushViewController:secondViewController animated:YES]

答案 2 :(得分:0)

每次执行模态segue时,都会丢失之前使用的UINavigationController。您需要做的是在视图中嵌入UINavigationController,表示您正在执行模态转换。

前几天查看question I answered,以帮助您更清楚地了解我所谈论的内容。

相关问题