Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更新tableview单元格中的文本并刷新后键盘关闭_Ios_Objective C_Uitableview_Uitextfield - Fatal编程技术网

Ios 更新tableview单元格中的文本并刷新后键盘关闭

Ios 更新tableview单元格中的文本并刷新后键盘关闭,ios,objective-c,uitableview,uitextfield,Ios,Objective C,Uitableview,Uitextfield,您好,我在customtableviewcell中有一个UILABEL和UIExtField。每次字符更改时,我都需要更新UILABEL。当我更新文本字段时,键盘中的每个字符都被忽略。我甚至尝试使用通知中心。任何快速的帮助都是感激的 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ [[

您好,我在customtableviewcell中有一个UILABEL和UIExtField。每次字符更改时,我都需要更新UILABEL。当我更新文本字段时,键盘中的每个字符都被忽略。我甚至尝试使用通知中心。任何快速的帮助都是感激的

- (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]带rowanimation:UITableViewRowAnimationFade]

它将
为您的文本字段退出FirstResponder
,并关闭键盘

唯一的解决方案是手动调整单元格高度和表格内容高度

这对我来说很好

 - (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;

    }
-(BOOL)textField:(UITextField*)textField应更改字符范围:(NSRange)范围替换字符串:(NSString*)字符串{
NSString*rateValue=[textField.text StringByReplacingCharactersRange:range with string:string];
NSCharacterSet*notAllowedChars=[[NSCharacterSet characterSetWithCharactersInString:@“1234567890”]逆变器集];
NSString*resultString=[[rateValue Components由字符分隔的集合:不允许的字符]Components由字符串连接:@”“];
[arrayRates replaceObjectAtIndex:textField.tagwithObject:resultString];
selectedTextField=textField;
selectedIndexPath=[NSIndexPath indexPathForRow:textField.tag目录:0];
customCell*cell=(customCell*)[self.tableView CellforRowatineXpath:selectedIndexPath];
NSString*乘数值=someValue;
如果([resultString IsequalString:@“0.0”])
cell.txtFieldRates.text=@;
其他的
cell.txtFieldRates.text=[NSString stringWithFormat:@“$%@”,resultString];
NSString*customerValue=[NSString stringWithFormat:@“%d”,[multiplierValue intValue]*[resultString intValue]*365];

如果(customerValue.intValue[selectedTextField becomeFirstResponder];每次调用此方法都会调用键盘,您可以从其他地方调用这行代码,例如-(void)textFieldDidBeginEditing:(UITextField*)textField{}为什么要重新加载单元格?开始编辑时获取标签的引用,并直接更新。Avi..已获取标签的实例,其工作正常,,,但单个字符会被读取两次