在我的类中使用shouldChangeCharactersInRange来捕获UITextField在uitableview中。shouldChangeCharactersInRange返回UITextField的第二个字符
问题是它没有得到第一个输入值并从第二个开始。
如果我输入 “123”,它仅示出了 “12”
这是我的代码:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
UITextField *utx = (UITextField *) textField;
UITableViewCell *cell = (UITableViewCell*)utx.superview.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
UITextField *utxtest = (UITextField *)[cell.contentView viewWithTag:20];
NSLog(@"utxtest %@", utxtest.text);
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ACCEPTABLE_CHARECTERS] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
return YES;
}
,在我的tableview:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITextField * utxtest = (UITextField *)[cell.contentView viewWithTag:20];
utxtest = self;
return cell;
}
当你说,而不是'123'它显示'23',那是什么?在NSLog语句中还是在UITableViewCell中? – AMI289 2014-11-02 10:30:32
它在nslog输出“utxtest 23” – 2014-11-02 10:32:54
它显示如果你NSLog的utx变量是什么? – AMI289 2014-11-02 10:44:22