What won't this work?

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

  1. cis4life macrumors regular

    Joined:
    Apr 4, 2008
    #1
    Code:
    -(IBAction)loginAction:(id)sender
    {
    	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
    	}
    	else
    	{
    		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."
    							   delegate:nil 
    							   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?

    Also,

    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

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #2
    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

    Joined:
    Apr 4, 2008
    #3
    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

    Cedric
     

Share This Page