0

I have a UIScrollView with 2 views, side by side, each of which covers the entire screen. They are moved to visible bounds on user's action, only one covering the screen at a time. Both of these views have multiple UITextFields. Working with the simulator, I fill in a textField in the first view and when I press the Tab key, the firstResponder is assigned to a textField in the other view. I understand that on using the device, the user will not be able to do that. But what if the user uses a bluetooth keyboard, or similar accessory? I do not want a textField, that is currently not visible to become firstResponder. Can this be done?

EDIT: I just remembered the canBecomeFirstResponder method. But how do I determine which textField is about to becomeFirstResponder?

4

1 回答 1

1

听起来问题不在于他们不应该能够在两个文本字段之间进行制表符,而是他们不应该能够编辑不可见的文本字段,他们应该能够进行制表符如果它们同时可见。

我不会限制选项卡,而是实现 UITextField 委托方法 -textFieldShouldBeginEditing:,它允许您返回一个布尔值,无论该文本字段是否应该成为第一响应者。

例如:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    //  Only edit if the text field is visible
    return !textField.isHidden;
}

您可能需要调整此代码以适应文本字段的“可见”状态。

于 2013-10-09T07:08:59.123 回答