成功登录后自定义SEGUE [英] Custom segue after successful login

查看:921
本文介绍了成功登录后自定义SEGUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的iOS编程初学者,所以请不要杀我:]。我有授权的,当我成功的授权,我想转到第二个视图的应用程序。当授权失败我显示警告。我的code的授权:

I'm a beginner in iOS programming, so please don't kill me :]. I have application with authorization and when I successful authorize I would like go to second view. When authorization fails I show alert. My code for the authorization:

- (IBAction)LoginClick:(id)sender {

    for(User *user in self.allUsers){
        if([user.userName isEqualToString:self.usernameTextField.text] && [user.password isEqualToString:self.passwordTextField.text]){
            // Logged in --> go to second view (TableView)
            [self performSegueWithIdentifier:@"LoginSegue" sender:self];
        }
        else{
            // Wrong password or username
            Alerts *alert = [Alerts new];
            [alert showAlert:LOGIN_ERROR];
        }
    }
}

我想看看一个简单的方法进行自定义转换(SEGUE),以第二种观点,当我成功登录,但我没有找到。现在,我有这样的情节提要:

I tried to look a simple way for custom transition (segue) to second view, when I successful log in, but I didn't find. Now I have this storyboard:

https://www.dropbox.com/s/dc8h4u920wgt47s/Screenshot%202014-03-03%2011.36.56.png

和code为浏览之间的过渡是:

And code for transition between View is:

[self performSegueWithIdentifier:@"LoginSegue" sender:self];

结果是错误:

的*终止应用程序由于未捕获的异常'NSGenericException,理由是:找不到赛格瑞导航控制器LoginSegue。推时,源控制器由UINavigationController的一个实例管理塞格斯只能用'

* Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'LoginSegue'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

这是什么问题?为什么我需要的东西,如导航器。我需要创建一个赛格瑞类?什么是解决这一问题最简单的方法?谢谢你。

What is the problem? Why I need something like "Navigation controller". I need to create a class for segue? What is the simplest way to solve this problem? Thank you.

编辑------- SOLUTION

EDIT ------- SOLUTION

感谢所有的帮助。我添加导航控制器到我作为初始视图的应用程序。而且我发现,这个定制赛格瑞使用自定义SEGUE与制作类是不必要的。最简单的方法解决了我的问题是连接ViewControllers(NOT BUTTON和第二的ViewController,所以我有它第一次...),并命名为推动SEGUE。这个名字我以前在这里code:

Thanks to all for help. I added navigation controller to my application as initial view. And I found, that use of a custom segue and making class for this custom segue is unnecessary. The simplest way for solution my problem is connect the ViewControllers (NOT BUTTON and second ViewController, so I had it first time...) and name the push segue. The name I used here in code:

- (IBAction)LoginClick:(id)sender {

    for(User *user in self.allUsers){
        if([user.userName isEqualToString:self.usernameTextField.text] && [user.password isEqualToString:self.passwordTextField.text]){
            // Logged in --> go to second view (TableView)
            [self performSegueWithIdentifier:@"LoginSegue" sender:self];
        }
        else{
            // Wrong password or username
            Alerts *alert = [Alerts new];
            [alert showAlert:LOGIN_ERROR];
        }
    }
}

混凝土进入:[自performSegueWithIdentifier:@LoginSegue发件人:个体经营];

Concrete here: [self performSegueWithIdentifier:@"LoginSegue" sender:self];

和所有伟大工程。当我登录正确传递和用户名,我重定向到第二个视图。

And all works great. When I login with correctly pass and username I'm redirected to second View.

推荐答案

该错误是告诉你,你不能使用这种类型的转型不使用导航控制器。

The error is telling you you can't use that type of transition without using a navigation controller.

只需拖动并从右键菜单中删除一个导航控制器,并将其设置在右边的属性部分的初始控制器。像这样:

Simply drag and drop a navigation controller from the right menu and set it as the Initial Controller in the properties section on the right. like so:

那么你的登录控制器连接为根视图控制器。那么这会为你工作。

Then connect your login controller as its root view controller. Then this will work for you.

最终的结果应该是这个样子:

The end result should look something like:

这篇关于成功登录后自定义SEGUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆