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

标签 ios objective-c uitableview uitextfield

嗨,我在customtableviewcell中有一个UILABEL和UITEXTFIELD。每次更改字符时我都需要更新UILABEL。当我更新文本字段键盘中的每个字符时,就关闭了..我什至尝试使用Notification Center。任何快速的帮助将是感激的

- (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并关闭键盘

唯一的解决方案是手动调整单元格高度和表格内容高度https://stackoverflow.com/a/33621733/1060785

关于ios - 从tableview单元格更新文本并刷新后关闭键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33628895/

相关文章:

iphone - UIGraphicsBeginImageContextWithOptions 中的 CGContextDrawImage 忽略了 UIEdgeInsets

iphone - 将大量数据插入 Core Data 需要多少时间

ios - 更新 CoreData 对象无法正常工作

iOS:使用另一个类中定义的 UITableViewCell 中按钮的选定状态填充数组

ios - 在加载时在 Swift 中为 TableView 单元格设置动画(Up into TableView)

ios - Facebook 分享对话框 : Permission Error - OAuth "Facebook Platform" "insufficient_scope (#200) Permissions error"

ios - 键盘未隐藏在 ios 中

ios - 如何在 EventKit 中使用 CalendarIdentifier 获取提醒?

ios - 如何使用核心数据遍历检索到的对象?

ios - 核心数据 - 通过 iCloud 保存和共享图像