如何为 iPhone Xcode 创建登录屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16415216/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:21:10  来源:igfitidea点击:

how to create login screen for iPhone Xcode

iphoneobjective-cxcode

提问by Arif YILMAZ

I am trying to learn objective c xcode programming and I have a small project to do. First of all, I am trying to do a simple login page, where user enters username and password. username and password are hardcoded in the program. so there is not much logic. but my problem is, how do you forward the screen if the login is correct?

我正在尝试学习客观的 c xcode 编程,并且我有一个小项目要做。首先,我正在尝试做一个简单的登录页面,用户在其中输入用户名和密码。用户名和密码在程序中硬编码。所以没有太多逻辑。但我的问题是,如果登录正确,您如何转发屏幕?

here is my code,

这是我的代码,

- (IBAction)btn_login_submit:(id)sender {
  if([_txt_username.text isEqual:@"rotanet"] && [_txt_username.text isEqual:@"rotanet"]){
      _lbl_result.text = @"correct";
  }
  else{
      _lbl_result.text = @"incorrect";
  }
}

I am using storyboard, and now I have only one view controller. Should I add another view controller or something else? and how do I forward to the next page from login?

我正在使用故事板,现在我只有一个视图控制器。我应该添加另一个视图控制器还是其他东西?以及如何从登录转发到下一页?

thanks

谢谢

回答by Anila

To push to another view you create another ViewController for example MyViewController and in your submit method you add:

要推送到另一个视图,您创建另一个 ViewController 例如 MyViewController 并在您的提交方法中添加:

MyViewController* viewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];

回答by o15a3d4l11s2

It is good to start reading for the Storyboard and Segues - once you get the basics you will find that it is really easy to use them.

开始阅读 Storyboard 和 Segues 是很好的——一旦你掌握了基础知识,你就会发现它们真的很容易使用。

A good tutorial to start with: link, link2

一个很好的教程入手:链接链接2

EDIT:Basically what you need to do is add a second ViewController, then CTRL-Drag from the first ViewController to the second one to create the segue. Once it is created, you can give it an identifier and then call [self performSegueWithIdentifier:@"SEGUEIDENTIFIER" sender:nil];in the if statement when the login is correct and you are done.

编辑:基本上你需要做的是添加第二个 ViewController,然后 CTRL-Drag 从第一个 ViewController 到第二个以创建 segue。一旦它被创建,你可以给它一个标识符,然后[self performSegueWithIdentifier:@"SEGUEIDENTIFIER" sender:nil];在登录正确并且你完成时调用if 语句。

回答by Bonnie

    if([_txt_username.text isEqual:@"rotanet"] && [_txt_username.text isEqual:@"rotanet"]){

          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];

          ViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

        [self presentModalViewController: viewController animated: YES];
    }