Question

I am trying to update a UITableViewCell dynamically from a UITextField by using the UItextfields delegate, however it's always a character behind.

So if I type the letter h into the UITextView nothing happens in the UITableViewCell however if I type another letter to its hi then in the UITableViewCell you only see h

This is my code

#pragma mark - UITextView delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    NSUInteger newLength = (textView.text.length - range.length) + text.length;

    if ([text isEqualToString:@"\n"]) {
        return NO;
    }

    if(newLength <= MAX_LENGTH)
    {
        if (filterTextView.tag == 1) {
            filterButtonsTableViewController.doorFilterString = textView.text;
            [filterButtonsTableViewController.tableView reloadData];
        } else if (filterTextView.tag == 2) {
            filterButtonsTableViewController.doorFilterString = textView.text;
            [filterButtonsTableViewController.tableView reloadData];
        }
        return YES;
    } else {
        return NO;
    }
}

How can I make it so that the UITableViewCell updates at the same time with the correct value?

Was it helpful?

Solution

As you are implementing shouldChangeTextInRange:, the text did not change yet. Try implementing textViewDidChange: or incorporate the changes given in replacementText:(NSString *)text in your implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top