Trying to find which text field is active ios

后端 未结 7 2353
Happy的楠姐
Happy的楠姐 2020-12-28 14:26

I am trying to find which textfield is active for when the I move the view when the keyboard rises. I am trying to set a property in my viewcontroller from the subview of a

7条回答
  •  爱一瞬间的悲伤
    2020-12-28 15:26

    You need to search for an object that has become a first responder. First responder object is the one using the keyboard (actually, it is he one having focus for user input). To check which text field uses the keyboard, iterate over your text fields (or just over all subviews) and use the isFirstResponder method.

    EDIT: As requested, a sample code, assuming all text fields are a subview of the view controller's view:

    for (UIView *view in self.view.subviews) {
        if (view.isFirstResponder) {
            [self doSomethingCleverWithView:view];
        }
    }
    

提交回复
热议问题