0

我正在为 iphone 制作一个带有多个页面的 xcode 应用程序。如何通过单击按钮切换到应用程序中的不同页面?

4

2 回答 2

0

正如 Aaron 所提到的,一种简单的方法是将视图控制器嵌入到导航控制器中。如果您正在使用情节提要,则在情节提要上选择您的视图控制器,然后单击菜单项编辑器 -> 嵌入 -> 导航控制器。为了尝试导航的工作方式,请通过 Control + 单击将登录视图控制器上的登录按钮中的 push segue 添加到另一个视图控制器(您要导航到的新“页面”将是情节提要上的另一个视图控制器) + 从按钮拖动到另一个视图控制器。

您还可以在没有 segue 的情况下以编程方式导航到另一个视图控制器。在单击登录按钮时调用的方法上,您可以像这样调用另一个视图控制器(新的“页面”):

// Create a new view controller
UIViewController *myController = [[UIViewController alloc] init];
// If you have the view controller defined in the storyboard, and you have give it a Storyboard Id, let's say "MyViewController", you can get it like this:
// UIViewController *myController = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];

// Push/Navigate to the new view controller
[self.navigationController pushNavigationController:myController animated:YES];

希望有帮助。

于 2013-03-08T21:07:22.440 回答
0

你可以使用这个:

UIViewController *viewControllerYouWant = [[UIViewController alloc] init];
[self presentViewController:viewControllerYouWant];

如果您触摸登录按钮,您将转到另一个视图。如果您在另一个视图上,请使用相同的代码,仅包括您要使用的视图控制器。

于 2013-03-08T21:13:27.877 回答