Following up a recent discussion, now I would like to find out how to setFocus on the searchfield, which has been created with the help of iOSKit sample code:
Dim sc As new UISearchController(nil)
//A few options are available here
sc.dimsBackgroundDuringPresentation = False
sc.hidesNavigationBarDuringPresentation = False
Dim scb As UIKit.UISearchBar = sc.searchBar
//A few options are available here
scb.placeholder = "Type something here..."
'scb.showsCancelButton = True
'scb.tintColor = UIColor.White
'scb.barTintColor = UIColor.Red
//Keep a reference to the searchbar
self.searchBar = scb
//Setup the searchfield delegate
scb.SetupDelegate
//Handler for search text changed
AddHandler scb.TextChanged, AddressOf handle_SearchTextChanged
AddHandler scb.CancelButtonPressed, AddressOf handle_SearchCancelled
AddHandler scb.SearchButtonPressed, AddressOf handle_SearchButtonPressed
Declare Function valueForKey_ Lib FoundationLib Selector "valueForKey:" (obj_id As ptr, key As CFStringRef) As ptr
Dim textfield As Ptr = valueForKey_(scb.handle, "searchField")
if textfield <> nil then
Declare Sub setTextColor Lib "UIKit.framework" Selector "setTextColor:" (obj_id As ptr, col As ptr)
setTextColor(textfield, UIColor.White)
End If
//Now attaching the searchbar to the navigation bar
Declare Function navigationItem Lib "UIKit.framework" Selector "navigationItem" (obj_ref As ptr) As ptr
Dim navItem As ptr = navigationItem(Self.ViewControllerHandle)
Declare Sub setSearchController Lib UIKitLib Selector "setSearchController:" (obj As ptr, ctrl As ptr)
setSearchController(navItem, sc)
//If necessary, set this
Declare Sub hidesSearchBarWhenScrolling Lib "UIKit" Selector "hidesSearchBarWhenScrolling" (obj As ptr, value As Boolean)
hidesSearchBarWhenScrolling(navItem, False)
I tried to add this shot in the dark, but as it is not working as expected I need some help now.
Dim vGotFocus As Boolean
Declare Function becomeFirstResponder Lib "UIKit" Selector "becomeFirstResponder" (obj_id As UInt64) As Boolean
vGotFocus=becomeFirstResponder(UInt64(scb.Handle))
I would like to set focus on the search field at startup of the app. How?