What won't this work?

Discussion in 'iOS Programming' started by cis4life, Jul 11, 2009.

  1. cis4life macrumors regular

    Apr 4, 2008
    	NSString *unStr = [[NSString alloc] initWithString:usernameField.text];
    	NSString *passStr = [[NSString alloc] initWithString:passwordField.text];
    	if([unStr compare:@"druser"] && [passStr compare:@"password"])
    		//Load Main View Here
    		UIAlertView *failAlert = [[UIAlertView alloc]
    							   initWithTitle:@"Login Failed"
    							   message:@"The username and password you supplied were not found in our system, please check your credentials and try again."
    							   cancelButtonTitle:@"Go Back" otherButtonTitles:nil];
    		[failAlert show];
    		[failAlert release];
    The code launches, but IF i type 'druser' and 'password' as the username and password, it launches the else code block??? Maybe I'm missing something?


    I have a UITextField, how do I mask it so that as I input text into it, it comes up like a password (the black circles instead of the actual text)
  2. lucasgladding macrumors 6502

    Feb 16, 2007
    Waterloo, Ontario
    You want isEqualToString: rather than compare:. compare: is for sorting purposes, with NSOrderedSame being the result when comparing equal strings. NSOrderedSame is equivalent to 0 or false, hence the else block being called.

    The secureTextEntry property is what you need for the password field. It's part of the UITextInputTraits protocol that UITextField conforms to.
  3. cis4life thread starter macrumors regular

    Apr 4, 2008
    Thanks a million,

    You Da Man. That worked like a charm. (still getting myself around all the ins and outs of coco touch and obj-c)

    But that worked like a charm


Share This Page