xcode 如何在 iPhone 的不同视图之间移动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5253055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to move between different views in iPhone
提问by developer
I have a Login view in my iPhone app. If the user successfully authenticates I want to move him from LoginViewController screen to MyViewController screen. Below is my code,
我的 iPhone 应用程序中有一个登录视图。如果用户成功通过身份验证,我想将他从 LoginViewController 屏幕移动到 MyViewController 屏幕。下面是我的代码,
if([serverOutput isEqualToString:@"Yes"]){
NSLog(@"Authentication correct");
if(self.myviewController==nil)
{
MyViewController *myController=
[[MyViewController alloc]initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];
self.myviewController=myController;
[myController release];
}
}
But somehow the app doesnt do anything when i click on the Login button even though the authentication is correct. As i am new to iphone app development can anybody please help me out with the code..
但不知何故,即使身份验证正确,当我单击“登录”按钮时,该应用程序也不会执行任何操作。由于我是 iphone 应用程序开发的新手,任何人都可以帮助我解决代码问题。
回答by Convolution
To transition between views you're going to want to read up on UINavigationControllers
. A UINavigationController
is an object that manages a hierarchy of views. The UINavigationController
is like a road map for going from one view to another in your applications flow and it achieves it's most basic features by calling the methods pushViewController:animated
(to transition to a new view controller) and popViewController:animated
(to transition back to the preview view).
要在您需要阅读的视图之间进行转换UINavigationControllers
。AUINavigationController
是管理视图层次结构的对象。这UINavigationController
就像在您的应用程序流中从一个视图转到另一个视图的路线图,它通过调用方法pushViewController:animated
(转换到新的视图控制器)和popViewController:animated
(转换回预览视图)来实现它的最基本功能。
In the case of your project you'd want to do the following.
对于您的项目,您需要执行以下操作。
- Allocate and initialize a
UINavigationController
(in your application delegate if you plan on the login screen to be where your program starts) and assign it's root view to your login view controller. - If the user has been successfully authenticated, you would then construct an instance of the
UIViewController
you want to transition to and then instruct theUINavigationController
to push this next view controller onto the navigation stack by callingpushViewController:animated:
- At this point lets say you want the user to log out and return to the login screen once again, you can call this method
popViewController:animated
.
- 分配并初始化一个
UINavigationController
(如果您计划在登录屏幕上作为程序启动的位置,则在您的应用程序委托中)并将它的根视图分配给您的登录视图控制器。 - 如果用户已成功通过身份验证,那么您将构造一个
UIViewController
您想要转换到的实例,然后UINavigationController
通过调用指示将下一个视图控制器推送到导航堆栈上pushViewController:animated:
- 此时假设您希望用户注销并再次返回登录屏幕,您可以调用此方法
popViewController:animated
。
Here'sthe class reference for UINavigationController
to get you started. It's got some great pictures explaining it's structure.
这是UINavigationController
帮助您入门的课程参考。它有一些很棒的图片解释了它的结构。
回答by hoha
Use UINavigationController
.
使用UINavigationController
.