简体   繁体   English

在同一 UITableView 的单元格中的 UITextFields 之间更改焦点

[英]Changing focus between UITextFields in cells at same UITableView

In my iPad application i have few UITableView on same view created programmatically.在我的 iPad 应用程序中,我在以编程方式创建的同一视图上几乎没有 UITableView。 They must pretend one multicolumn table.他们必须假装一张多列表。 Each cell contains UITextField.每个单元格都包含 UITextField。 It's size is equal to cell's size (its the reason why i cant get UITableView's delegate methods didSelect/didDeselect row).它的大小等于单元格的大小(这是我无法获得 UITableView 的委托方法 didSelect/didDeselect 行的原因)。 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这是我在 Cell 类中的 UITextField Delegate 方法

- (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 .这可能是由autocapitalizationType引起的。 Your have to dismiss the auto correction before getting your textField becomeFirstResponder .在获取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.如果第一次点击后调用textFieldShouldBeginEditing并且您返回YES则文本字段开始编辑。 Probably you are making endEditing to the whole tableView after that.在那之后,您可能正在对整个tableView进行endEditing

If you call endEditing on the specific cell in your cell's delegate instead of the whole table view it should work.如果您在单元格委托中的特定单元格上调用endEditing而不是整个表格视图,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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