HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

iOS App - Interface for user log in using a call to a web service API

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
appiosuserloginterfacecallserviceforusingweb

Problem

I have a navigation controller set up with a user code and password and a log in button. When the user clicks on the Log In button or the return key on the keyboard on the password text box - the program checks if the user code and / or password is blank. It then goes off and calls a Web API running on a server to see if the user and password are valid. If it is, it goes to the next view controller - I created a segue between the two view controllers and named it.

This now works for me but because I'm new to this I'd love if someone could have a quick look at my code and see if I am doing anything I shouldn't be doing. I'm worried about memory problems and is it good practice to disable the screen while the system waits for the web service to return.

Any guidance would be much appreciated:

```
// when the user clicks the return key on the user code - the focus goes to the password
  • (IBAction)txtUserDidEndOnExit:(id)sender {


[sender resignFirstResponder];
[_txtPassword becomeFirstResponder];
}

// when the user clicks the return key on the password - it performs the click on the log in button
  • (IBAction)txtPasswordDidEndOnExit:(id)sender {


[sender resignFirstResponder];
[_butLogin sendActionsForControlEvents:UIControlEventTouchUpInside];
}

  • (IBAction)butLoginClick:(id)sender {


[self logIn];
}

  • (void) logIn {



// check if the user code is blank - if it is - tell the user and stop the log in
if ([self.txtUser.text length] == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error" message:@"User Required" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

alert.tag = TAG_USER;
[alert show];
return;
}

// check if the password is blank - if it is - tell the user and stop the log in
if ([self.txtPassword.text length] == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error" message:@"Password Required" delegate:self cancelBut

Solution

When you have something like this in your code:

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


You can simply delete all 5 of these lines. The only reason to include the the stub for - (void)didReceiveMemoryWarning is if you're actually going to add code to the method.

int returnval


This variable should be renamed as returnVal.

#define TAG_USER 1
#define TAG_PWD 2
#define TAG_SETTINGS 3


There's no reason why this shouldn't be an enum:

typedef NS_ENUM(NSInteger, UITAGS) {
    TAG_USER      1,
    TAG_PWD       2,
    TAG_SETTINGS  3
};

Code Snippets

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
int returnval
#define TAG_USER 1
#define TAG_PWD 2
#define TAG_SETTINGS 3
typedef NS_ENUM(NSInteger, UITAGS) {
    TAG_USER      1,
    TAG_PWD       2,
    TAG_SETTINGS  3
};

Context

StackExchange Code Review Q#44329, answer score: 8

Revisions (0)

No revisions yet.