Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Navigate TableView with Arrow Keys

How can a UITableView be navigated with arrow keys (physical keyboard) much like the spotlight behavior that was introduced in iOS 10?

Looking to have a user type into a search box and use the up/down arrow to highlight a row in a tableview and press return key to select the row.

I have not found any resources on the topic.

Please provide sample code in Swift.

like image 391
Michael Voccola Avatar asked Feb 11 '26 22:02

Michael Voccola


1 Answers

Did not try it, but this could be the answer for you.

  self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: true)

and use the text field delegate to handle return.

Edit: For highlighting use

tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!

and update your cell visual

like image 68
Luzo Avatar answered Feb 14 '26 14:02

Luzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!