Eric Chen
Eric Chen

Reputation: 1

how to deal with the keyboard button which name is "done" in ios

now i have a textField.

and i enter some words,the keyboard will appear.

when i pressed the keyboard "done",the keyboard will disappear. (i have finished this function)

but next,

i want to insert data using core data framework when the user pressed the button "done"

so,how to solve this problem?

i know how to insert data using core data,so you do not need to tell me how to insert the data.

i am using this code to disappear keyboard.

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  [txtName resignFirstResponder];
  return YES;
}

thanks everybody

Upvotes: 0

Views: 3378

Answers (1)

Black Frog
Black Frog

Reputation: 11713

In the example code, I have 3 UITextField. You can process your update after we reach the last field

// I the tag property to indicate which field I am on during runtime
enum {
    Line1Tag = 50,
    Line2Tag,
    Line3Tag
};

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    // The user has pressed the "Return Key"
    // Which I have set to "Next" for first two lines
    // and "Done" for the last line, so jump to the next text field
    NSLog(@"\"Return\" key pressed.");

    // based on which text field we are in jump to the next
    if (textField.tag == Line3Tag)
        // We have reach the last line so hide keyboard
        [textField resignFirstResponder];

        // this is where you can perform Core Data updates if you like

    else {
        int nextTag = textField.tag + 1;
        UIView *nextField = [self.view viewWithTag:nextTag];
        [nextField becomeFirstResponder];

        // Once the next text field is the first responder
        // I need to make sure the user can see it
        [self makeActiveTextFieldVisible];
    }
    return NO;
}

Upvotes: 2

Related Questions