isFirstResponder (HasFocus)

I want to be able to test if a TextField or TextArea has the focus. So I looked into the iOS Dev library and found at

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIResponder_Class/index.html#//apple_ref/occ/instm/UIResponder/isFirstResponder

NSObject
UIResponder
isFirstResponder

In Swift and OC, the example is as such :

[code]
isFirstResponder
Returns a Boolean value indicating whether the receiver is the first responder.

Declaration
SWIFT
func isFirstResponder() -> Bool
OBJECTIVE-C

  • (BOOL)isFirstResponder
    Return Value
    YES if the receiver is the first responder, NO otherwise.[/code]

So I built this :

  declare function isFirstResponder lib UIKit selector "isFirstResponder" (obj_id as Uint32) as boolean

To know if the control has focus, go boolean = isFirstResponder(UInt32(TextField1.handle))

If true, the TF or TA has the focus.

I do not understand the term “FirstResponder”. I have not run across anything that indicates it is anything expect “THE Responder”. Either a control is FirstReponder, or its not, and there can only be one (yeah I watched the Highlander)

But “FirstReponder” infers that there is a “SecondResponder”

[quote=152700:@Dave S]I do not understand the term “FirstResponder”. I have not run across anything that indicates it is anything expect “THE Responder”. Either a control is FirstReponder, or its not, and there can only be one (yeah I watched the Highlander)

But “FirstReponder” infers that there is a “SecondResponder”[/quote]

Well. There is a nextResponder described at the page I posted.

[code]nextResponder
Returns the receiver’??s next responder, or nil if it has none.

Declaration
SWIFT
func nextResponder() -> UIResponder?
OBJECTIVE-C

  • (UIResponder *)nextResponder
    Return Value
    The next object in the responder chain to be presented with an event for handling.

Discussion
The UIResponder class does not store or set the next responder automatically, instead returning nil by default. Subclasses must override this method to set the next responder. UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t); UIViewController implements the method by returning its view’s superview; UIWindow returns the application object, and UIApplication returns nil.[/code]

There is always one responder, but they can be several in succession…

To do a “setFocus” of a TextField in iOS:

declare function becomeFirstResponder lib "UIKit" selector "becomeFirstResponder" (obj_id as Uint32) as boolean

Called like this

vHasFocus=becomeFirstResponder(UInt32(TextField.handle))  //vHasFocus does not seem to get proper result

And here as a method:

[code]Public Sub SetFocusiOS(extends vCtrl as iOSControl)
Dim vGotFocus as Boolean

#if Target32Bit
declare function becomeFirstResponder lib “UIKit” selector “becomeFirstResponder” (obj_id as Uint32) as boolean
vGotFocus=becomeFirstResponder(UInt32(vCtrl.handle))
#endif

#if Target64Bit
declare function becomeFirstResponder lib “UIKit” selector “becomeFirstResponder” (obj_id as UInt64) as boolean
vGotFocus=becomeFirstResponder(UInt64(vCtrl.handle))
#endif

End Sub[/code]

There is a so called responder chain. And the FirstResponder is the first in that chain.
See Understanding Responders and the Responder Chain

Hi Dan
If this SetFocus works or no.
i try but no works.
Errors

Asamblea_Reg.SetFocusiOS Declaration
The extends modifier cannot be used on a class method
Sub SetFocusiOS(extends vCtrl as iOSControl)

Asamblea_Reg.ClsData, line 12
This method extends class iOSControl, but the base expression is class Asamblea_Reg.Asamblea_Reg.
SetfocusiOS(TxtBuscar.Handle)

[quote=468153:@Alexis Colon Lugo]Hi Dan
If this SetFocus works or no.
i try but no works.
Errors

Asamblea_Reg.SetFocusiOS Declaration
The extends modifier cannot be used on a class method
Sub SetFocusiOS(extends vCtrl as iOSControl)

Asamblea_Reg.ClsData, line 12
This method extends class iOSControl, but the base expression is class Asamblea_Reg.Asamblea_Reg.
SetfocusiOS(TxtBuscar.Handle)[/quote]
We need to see some code. The function he posted works

Dim vGotFocus as Boolean

#if Target32Bit
declare function becomeFirstResponder lib “UIKit” selector “becomeFirstResponder” (obj_id as Uint32) as boolean
vGotFocus=becomeFirstResponder(UInt32(vCtrl.handle))
#endif

#if Target64Bit
declare function becomeFirstResponder lib “UIKit” selector “becomeFirstResponder” (obj_id as UInt64) as boolean
vGotFocus=becomeFirstResponder(UInt64(vCtrl.handle))
#endif
error

Asamblea_Reg.SetFocusiOS Declaration
The extends modifier cannot be used on a class method
Sub SetFocusiOS(extends vCtrl as iOSControl)

The error has nothing to do with your declares (fyi, you can dump the 32bit version)
but has to do with exactly what the error message says…

You cannot extend a class method… not in iOS, nor Desktop…

ok
thanks