嗨,我在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/