从 tableview 单元格更新文本并刷新后键盘关闭

keyboard dismissing after updating text from tableview cell and refreshing

您好,我有一个 UILABEL 和 UITEXTFIELD customtableviewcell.I 需要更新每个字符的 UILABEL change.As 我更新文本字段中的每个字符键盘正在关闭..我什至尝试使用通知中心。任何快速帮助将不胜感激

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    NSString *rateValue=[textField.text stringByReplacingCharactersInRange:range withString:string];

    NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890"] invertedSet];

    NSString *resultString = [[rateValue componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];

    [arrayRates replaceObjectAtIndex:textField.tag withObject:resultString];
    selectedTextField=textField;
    selectedTxtFieldPath = [NSIndexPath indexPathForRow:textField.tag inSection:0];
    [self.tableViewSkuVoids beginUpdates];
    [self.tableViewSkuVoids reloadRowsAtIndexPaths:@[selectedTxtFieldPath] withRowAnimation:UITableViewRowAnimationFade];
    [self.tableViewSkuVoids endUpdates];
    [[self.tableViewSkuVoids superview]  endEditing:NO];

   [[NSNotificationCenter defaultCenter] postNotificationName:@"keyboardWillShow" object:nil userInfo:nil];

   [selectedTextField becomeFirstResponder];
   return YES;
}

当您使用

重新加载单元格时

[self.tableViewSkuVoids reloadRowsAtIndexPaths:@[selectedTxtFieldPath] withRowAnimation:UITableViewRowAnimationFade];

它将 resignFirstResponder 用于您的文本字段,并关闭键盘

唯一的解决办法是手动调整单元格高度和table内容高度

这很适合我

 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

        NSString *rateValue=[textField.text stringByReplacingCharactersInRange:range withString:string];

        NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890"] invertedSet];

        NSString *resultString = [[rateValue componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];

        [arrayRates replaceObjectAtIndex:textField.tag withObject:resultString];

        selectedTextField=textField;

        selectedIndexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0];

        customCell *cell=(customCell *)[self.tableView cellForRowAtIndexPath: selectedIndexPath];

        NSString *multiplierValue=someValue;

        if ([resultString isEqualToString:@"0.0"])
            cell.txtFieldRates.text=@"";
        else
            cell.txtFieldRates.text=[NSString stringWithFormat:@"$ %@",resultString];

        NSString *customerValue=[NSString stringWithFormat:@"%d",[multiplierValue intValue]*[resultString intValue]*365];

        if (customerValue.intValue<=0)
            cell.lblCustomer.text=@"";
        else
            cell.lblCustomer.text=[NSString stringWithFormat:@"$ %@", customerValue];


           return NO;

    }