0

I am new to IOS. I created a simple storyboard layout, something as shown below:

-> Navigation --> login --> Welcome screen

When I build and run the setup, I can see the login page with username and password textfields and a button ('login').

But I am unable to understand How I should redirect the page to welcome screen when the user has entered something inside the username and password textfields.

To achieve this, I added a controller LoginViewController to the login page and inside that controller's .h file, I added the following code:

#import "LoginViewController.h"

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *username_text;
@property (weak, nonatomic) IBOutlet UITextField *pwd_text;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)login_btn:(id)sender {
    if([self validOrNot]){
//        UIviewcontrollerWelcom *vc = [[DashboardViewController alloc] init];
//        [self presentViewController:vc animated:YES completion:nil];

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:WelcomeViewController];
        [self presentViewController:navigationController animated:YES completion: nil];

    }
}
- (BOOL)validOrNot{
    if ([self.pwd_text hasText] && [self.username_text hasText]) {
        return YES;
    }
    else
    {
        return NO;
    }
}

Please guide me how should I redirect to next page which is welcome screen when user enter something in username and password textfields of the login page.

Mr_Green
  • 40,727
  • 45
  • 159
  • 271

2 Answers2

3

Give the storyboard id for the welcome page view controller in the storyboard.

And you can present the welcome page view controller with the following line of code:

 WelcomeViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"WelcomeView"];

 [self presentViewController:vc animated:YES completion:nil];

For setting up the storyboard ID, see this link :

Community
  • 1
  • 1
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
1

Try out this:

- (IBAction)login_btn:(id)sender {
   if([self validOrNot]){
 WelcomeViewController *wVC = [[WelcomeViewController alloc]init];

 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self];
[navigationController pushViewController:wVC animated:YES];


}
}
Shubham Ojha
  • 461
  • 5
  • 17
  • I am getting error, `use of undeclared identifier wVC`. I think `WelcomeViewController` is somehow unrecognizable. What should I do to make it recognizable? – Mr_Green Aug 14 '15 at 19:06
  • Import WelcomeViewController in your LoginViewController.h file with a #import "WelcomeViewController.h" statement – Shubham Ojha Aug 14 '15 at 19:07
  • Thanks it is working.. but why it is redirecting me to welcome page when I don't enter anything in the username and password fields? It is not redirecting to welcome page when I enter something in those fields. – Mr_Green Aug 14 '15 at 19:38
  • Which iOS version are you using?? – Shubham Ojha Aug 14 '15 at 19:53