Database Reference
In-Depth Information
Now we need to implement one of the UITextField delegate methods called textFieldShouldReturn: .
You have already done this before so it should be familiar.
#pragma mark - UITextFieldDelegate Methods
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
if([textField isEqual:_txtFirstName]){
[_txtLastName becomeFirstResponder];
} else if([textField isEqual:_txtLastName]){
if([_txtDisplayName.text isEqualToString:@""])
_txtDisplayName.text =
[NSString stringWithFormat:@"%@ %@",_txtFirstName.text,_txtLastName.text];
[_txtDisplayName becomeFirstResponder];
} else if([textField isEqual:_txtDisplayName]){
[_txtFavoriteNumber becomeFirstResponder];
} else if([textField isEqual:_txtFavoriteNumber]){
[_txtFavoriteNumber resignFirstResponder];
}
return YES;
}
Here we check the text field and move to the next text field similar to what we have done in the past.
The only difference here is that right before we move to the _txtDisplayName field we check to see if it is
empty. If it is, we autofill the display name with a concatenated value of the first name and second name.
Now we will add some Bar Button methods:
#pragma mark - Bar Button Methods
-(void)btnEditPressed:(id)sender {
[self enableAllFields];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:self action:@selector(btnDonePressed:)];
[self.navigationItem setRightBarButtonItem:doneButton animated:YES];
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
}
-(void)btnDonePressed:(id)sender {
[self disableAllFields];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit"
style:UIBarButtonItemStyleBordered target:self action:@selector(btnEditPressed:)];
[self.navigationItem setRightBarButtonItem:editButton animated:YES];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered target:self action:@selector(btnBackPressed:)];
[self.navigationItem setLeftBarButtonItem:backButton animated:YES];
}
-(void)btnBackPressed:(id)sender {
[_delegate detailViewControllerDidClose:self];
}
 
Search WWH ::




Custom Search