Q:

UITextField keyboard return button should change as Done button

I am having five number of textFields, say textField1,textField2,textField3,textField4,textField5.
What i want to do is that the UITextField keyboard return  button should change as Done button   when all the textField contains some text.
 I have tried,
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if([textField1.text doubleValue]!=0)
        if([textField2.text doubleValue]!=0)
            if([textField3 doubleValue]!=0)
                if([textField4 doubleValue]!=0)
                    if([textField5 doubleValue]!=0)
                    {
                        [textField setReturnKeyType:UIReturnKeyDone];
                    }
                    else
                        [textField setReturnKeyType:UIReturnKeyDefault];
                    else
                        [textField setReturnKeyType:UIReturnKeyDefault];
                    else
                        [textField setReturnKeyType:UIReturnKeyDefault];
                    else
                        [textField setReturnKeyType:UIReturnKeyDefault];
                    else
                        [textField setReturnKeyType:UIReturnKeyDefault];
}

I also tried in 
- (void)textFieldDidEndEditing:(UITextField *)textField
{
}

Both are not working... Please anyone help me...

A:

you better play with textFieldShouldBeginEditing, here just check all the textfields are contains non null values,
so code should look like this
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if([[tf1.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] > 0 && [[tf2.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] > 0 [[tf3.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] > 0) {
        [textField setReturnKeyType:UIReturnKeyDone];
    }
    return TRUE;
}

//// EDIT 
I've checked this code. It works fine. so try this and lemme know.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if ([self areAllFieldsNonEmpty]) {
        [textField setReturnKeyType:UIReturnKeyDone];
        [textField reloadInputViews];
    } else {
        [textField setReturnKeyType:UIReturnKeyDefault];
        [textField reloadInputViews];
    }
    return TRUE;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if ([self areOtherFiledsNonEmptyThan:textField]) {
        if (range.location == 0 && range.length == 0) {
            [textField setReturnKeyType:UIReturnKeyDone];
            [textField reloadInputViews];
        } else if (range.location == 0 && range.length == 1) {
            [textField setReturnKeyType:UIReturnKeyDefault];
            [textField reloadInputViews];
        }
    }
    return TRUE;
}

- (NSInteger)lengthOf:(UITextField *)tf {
    return [[tf.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length];
}

- (BOOL)areOtherFiledsNonEmptyThan:(UITextField *)tf {
    BOOL isEmpty = TRUE;
    for (UITextField *textField in self.view.subviews) {
        if ([textField isKindOfClass:[UITextField class]] && tf != textField) {
            if ([self lengthOf:textField] == 0) {
                isEmpty = FALSE;
                break;
            }
        }
    }
    return isEmpty;
}

- (BOOL)areAllFieldsNonEmpty {
    BOOL isEmpty = TRUE;
    for (UITextField *textField in self.view.subviews) {
        if ([textField isKindOfClass:[UITextField class]]) {
            if ([self lengthOf:textField] == 0) {
                isEmpty = FALSE;
                break;
            }
        }
    }
    return isEmpty;
}

