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!
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

Sinan the Thinker
7,980 PointsI 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
4 Answers

Stone Preston
42,016 Pointslog 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)
{

Sinan the Thinker
7,980 PointsThe alertview i see is :
UIAlertView *alertView = [[ UIAlertView alloc] initWithTitle:@"Leeg veld" message:@"Vul de lege velden in" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

Sinan the Thinker
7,980 PointsStone 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
42,016 Pointsremove the connections to the text fields and add them again.

Sinan the Thinker
7,980 PointsStone, 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
42,016 Pointsyeah if you change the name of a connected property after adding it, you have to remove the old connection and add it again.
Stone Preston
42,016 PointsStone Preston
42,016 Pointswhich 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: