Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

I keep getting alertview in signupviewcontroller

Hi guys,

I am now trying a variation of the sign up, but i keep getting the alertview, while i have specified -like in the course- just to show the alertview when the length of one of the inputsfields are 0. Even when every inputfield is filled in, I keep getting this error, who can help me solve this?

Here is the signup.m:

//
//  SignUpViewControllerLeverancier.m
//  SIKA
//
//  Created by BLANCO on 25-04-14.
//  Copyright (c) 2014 Sinan Karakurt. All rights reserved.
//

#import "SignUpViewControllerLeverancier.h"
#import <Parse/Parse.h>

@interface SignUpViewControllerLeverancier ()

@end

@implementation SignUpViewControllerLeverancier


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



- (IBAction)signupLeverancier:(id)sender {

    NSString *naamLeverancier = self.naamLeverancierField.text ;

    NSString *telefoonLeverancier = [self.telefoonLeverancierField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSString *bedrijfsnaamLeverancier = self.bedrijfsnaamLeverancierField.text;

    NSString *adresLeverancier = self.adresLeverancierField.text;

    NSString *postcodeLeverancier = self.postcodeLeverancierField.text;

    NSString *stadLeverancier = self.stadLeverancierField.text;

    NSString *emailLeverancier = [self.emailLeverancierField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSString *wachtwoordLeverancier = [self.wachtwoordLeverancierField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    if  ([naamLeverancier length] == 0 ||
         [telefoonLeverancier length] == 0 ||
         [bedrijfsnaamLeverancier length] == 0 ||
         [adresLeverancier length] == 0 ||
         [postcodeLeverancier length] == 0 ||
         [stadLeverancier length] == 0 ||
         [emailLeverancier length] == 0 ||
         [wachtwoordLeverancier length] == 0)
    {

        UIAlertView *alertView = [[ UIAlertView alloc] initWithTitle:@"Leeg veld" message:@"Vul de lege velden in" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

        [alertView show];
            }

 else {
PFUser *newUserLeverancier = [PFUser user];
newUserLeverancier[@"naamLeverancier"] = naamLeverancier;
        newUserLeverancier[@"telefoonLeverancier"]= telefoonLeverancier;
        newUserLeverancier.username = bedrijfsnaamLeverancier;
        newUserLeverancier[@"adresLeverancier"] = adresLeverancier;
        newUserLeverancier[@"postcodeLeverancier"] = postcodeLeverancier;
        newUserLeverancier[@"stadLeverancier"] = stadLeverancier;
        newUserLeverancier.email = emailLeverancier;
        newUserLeverancier.password = wachtwoordLeverancier;

       [newUserLeverancier signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error) {
               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
            }
           else {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
        }];
 }
}
@end
Stone Preston
Stone Preston
42,016 Points

which alertView are you seeing? this one:

UIAlertView *alertView = [[ UIAlertView alloc] initWithTitle:@"Leeg veld" message:@"Vul de lege velden in" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

or this one:

 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];

4 Answers

Stone Preston
Stone Preston
42,016 Points

log the length of all your Strings before the if statement runs. that way you can see which text field is causing the issue

NSLog("naamLeveracier length: %@", naamLeveracier);
NSLog("telefoonLeveracier length: %@", telefoonLeveracier);
//etc etc


 if  ([naamLeverancier length] == 0 ||
         [telefoonLeverancier length] == 0 ||
         [bedrijfsnaamLeverancier length] == 0 ||
         [adresLeverancier length] == 0 ||
         [postcodeLeverancier length] == 0 ||
         [stadLeverancier length] == 0 ||
         [emailLeverancier length] == 0 ||
         [wachtwoordLeverancier length] == 0)
    {

The alertview i see is :

UIAlertView *alertView = [[ UIAlertView alloc] initWithTitle:@"Leeg veld" message:@"Vul de lege velden in" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

Stone thanks for your reply,

I ve tried that; I get by a test of the 4 fields for all of them "null"; which means that they are not right connected with the signupviewcontroller? But I checked I have all the properties in the .h file AND the class is in the mainstoryboard set to signupviewcontrollerleverancier...I have some other viewcontrollers in the mainstoryboard which are excluded the the tab bar and navigation view controllers....could this be causing a problem?

2014-04-25 17:28:07.921 SIKA[35899:60b] naamLevenracier length: (null)
2014-04-25 17:28:07.923 SIKA[35899:60b] telefoonLevenracier length: (null)
2014-04-25 17:28:07.923 SIKA[35899:60b] bedrijfsnaamLeverancier length: (null)
2014-04-25 17:28:07.923 SIKA[35899:60b] telefoonLeverancier length: (null)
Stone Preston
Stone Preston
42,016 Points

remove the connections to the text fields and add them again.

Stone, that was the golden tip! thanks!

I see now what the problem caused; I had initially connected the mainstoryboard with the .h-properties. And after that I had changed the names of the fields, xcode didnt get the new names of the fields I think.

Stone Preston
Stone Preston
42,016 Points

yeah if you change the name of a connected property after adding it, you have to remove the old connection and add it again.