简体   繁体   中英

Changing focus between UITextFields in cells at same UITableView

In my iPad application i have few UITableView on same view created programmatically. They must pretend one multicolumn table. Each cell contains UITextField. It's size is equal to cell's size (its the reason why i cant get UITableView's delegate methods didSelect/didDeselect row). My problem is when i begin edit one text field then try to remove focus to other textfield it needs two taps. After first tap no one of cell is not editing. Such behavior observing only inside same table. If i want to change focus to other table its possible in one tap. What i missed?

Here is my UITextField Delegate methods in Cell's class

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if ([_delegate checkForAccess:self]) {
        if (!((CTKTextField *)textField).isEditable)
        {
            [_delegate callPickerUnderCell:self];
            return NO;
        }
        else
        {
            [_delegate getPosition:self];
            return YES;
        }
    }
    else return NO;
}

-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    if (_textField.text.length == -1)
    {
        _textField.rightView = nil;
    }
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSString *input = textField.text;

    [_delegate saveEdit:self withText:input];
}

That might be caused by autocapitalizationType . Your have to dismiss the auto correction before getting your textField becomeFirstResponder . Disable it will solve the problem.

textField.autocapitalizationType = UITextAutocapitalizationTypeNone;

Edit: I was confused, try this one:

textField.autocorrectionType = UITextAutocorrectionTypeNo;

尝试将 UITableViewCellSelectionStyleNone 设置为带有文本字段的表格视图单元格。

If textFieldShouldBeginEditing is called after first tap and you return YES then text field starts editing. Probably you are making endEditing to the whole tableView after that.

If you call endEditing on the specific cell in your cell's delegate instead of the whole table view it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM