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];
}
}
}
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
And code for transition between View is:
[self performSegueWithIdentifier:@"LoginSegue" sender:self];
The result is error:
* 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.
EDIT ------- SOLUTION
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];
}
}
}
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.