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?
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
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];
}
To push to another view you create another ViewController for example MyViewController and in your submit method you add:
MyViewController* viewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
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.
A good tutorial to start with: link , link2
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.