Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Matthew Krueger
18,416 PointsRibbit signUpViewController viewDidLoad method being called twice.
In my Ribbit app I have an NSLog in the viewDidLoad method of my signUpViewController. When I click the "Sign Up" button on my login screen when the app is running the Log in screen pops over, waits a second, then pops over a second time. Additionally, there are two outputs in the console from the NSLog in the viewDidLoad. I can't seem to find a cause for this.
Everything works fine. This is just an annoyance.
Any help is appreciated.
Thanks, Matthew
Here is the code:
LoginViewController.m
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)signUp:(id)sender {
[self performSegueWithIdentifier:@"showSignUp" sender:self];
}
- (IBAction)login:(id)sender {
[PFUser logInWithUsernameInBackground:self.usernameField.text password:self.passwordField.text block:^(PFUser *user, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Make sure you have entered a valid username and password." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}
else{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
}
@end
SignUpViewController.m
@implementation SignupViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"Sing up view loaded.");
}
- (IBAction)signup:(id)sender {
NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *email = [self.emailField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (username.length == 0 || password.length == 0 || email.length == 0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Make sure you have entered a username, password, and email." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}
else{
PFUser *newUser = [PFUser user];
newUser.username = username;
newUser.password = password;
newUser.email = email;
[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Make sure you have entered a username, password, and email." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}
else{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
}
}
@end