I use [row.cellConfigAtConfigure setObject:@(5) forKey:XLFormTextViewMaxNumberOfCharacters] invaild
row = [XLFormRowDescriptor formRowDescriptorWithTag:kHouseTitle rowType:XLFormRowDescriptorTypeTextView title:@"HouseTitle"];
row.value = self.houseInfo.title;
[row.cellConfigAtConfigure setObject:@(5) forKey:XLFormTextViewMaxNumberOfCharacters];
[section addFormRow:row];
因为我需要不同的行长度。 现在我找到了处理它的方法。
-(UITextField *)getCurrentTextFiledWithRow:(XLFormRowDescriptor *)row {
XLFormBaseCell *cell = [row cellForFormController:self];
if ([cell isKindOfClass:[XLFormTextFieldCell class]]) {
XLFormTextFieldCell *xlFormTextFieldCell = (XLFormTextFieldCell *)cell;
return xlFormTextFieldCell.textField;
}
else {
return nil;
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
XLFormRowDescriptor *buildingAreaRow = [self.form formRowWithTag:kBuildingArea];
XLFormRowDescriptor *livingAreaRow = [self.form formRowWithTag:kLivingArea];
XLFormRowDescriptor *housePriceRow = [self.form formRowWithTag:kHouseCellingPrice];
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if ([self getCurrentTextFiledWithRow:buildingAreaRow] == textField) {
if(newString.length > 4){
return NO;
}
}
else if ([self getCurrentTextFiledWithRow:livingAreaRow] == textField) {
// TODO
}
else if([self getCurrentTextFiledWithRow:housePriceRow] == textField) {
//TODO
}
return YES;
}
你可以这样使用,我猜
NSString *const XLFormTextViewMaxNumberOfCharacters = @"textViewMaxNumberOfCharacters";
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (self.textViewMaxNumberOfCharacters)
{
// Check maximum length requirement
NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
if (newText.length > self.textViewMaxNumberOfCharacters.integerValue) {
return NO;
}
}
//perform based on your need
return [self.formViewController textView:textView shouldChangeTextInRange:range replacementText:text];
}