1

I have added textfields dynamically to scrollview as below:-

for(int i = 0; i< responseBillPay.billerDetails.payeeFormat.count; i++) {
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, y, width, height)];
    textField.borderStyle = UITextBorderStyleRoundedRect;

    textField.placeholder = [responseBillPay.billerDetails.payeeFormat[i] name];
    textField.delegate = self;
  [innerScroll addSubview:textField];
}

Now i want to set maximum length to each textfield.How could I do this? I got the response of webservice as :-

payeeFormat =         
          (

         {

            displayFlag = false;
            length = 4;
            name = "BU(Billing Unit)";
            validation = "Please enter 4 digits BU(Billing Unit)";
        },
                    {
            displayFlag = false;
            length = 2;
            name = "PC(Processing Cycle)";
            validation = "Please enter only numbers in PC(Processing Cycle),PC(Processing Cycle) should be maximum 2 digits,PC(Processing Cycle) should be minimum 1 digit";
        },
                    {
            displayFlag = true;
            length = 12;
            name = "Consumer No.";
            validation = "Consumer No. should be maximum 12 digits,Consumer No. should be minimum";
        }
    );
PK20
  • 1,066
  • 8
  • 19
poojathorat
  • 1,200
  • 2
  • 9
  • 19

2 Answers2

0

You can make it dynamic little bit according to you. like text range or placeholder text etc

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string];

    NSString *placeHOlder = textField.placeholder;

    if ([placeHOlder isEqualToString:@"BU(Billing Unit)"]) {
        if ([searchStr length] <= 4) {
            return YES;
        }
        else
            return NO;
    }
    else 
        return NO;
}

2nd Way

You can store all textfield in a array and you can check that text field in the above delegate method. If it is equal then put your text range and return YES otherwise return NO.

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
0

You can also subclass UITextField and add the attributes that you care about directly to the subclass as properties according to your payee response.

farhadf
  • 1,918
  • 3
  • 19
  • 27