TVDN TVDN -5 years ago 152
Swift Question

How to have DidSelectRow activate keyboard?


I want to have a keyboard (custom) to show when I click on a cell in my tableview and have said keyboard edit a label in the selected cell.

What I have read and tried

Stack overflow and other searched threads/tutorials

  1. A Swift example of Custom Views for Data Input (custom in-app keyboard)

  2. How to make custom keyboard only for my app in Swift?

  3. iOS 8: Creating a Custom Keyboard in Swift

Along with other results and searches (also the recommended readings within these threads), these were great for me getting the keyboard the way I want it (which is app-specific, I don't want to have the user install the keyboard to use the app), however, none explain how I could "activate" the keyboard without a textfield.

My thought process is this: I will have a keyboard with a textfield in place in order to receive the input from the keys pressed. This input would then be sent to the label that is in the selected cell. The problem is in the keyboard showing without anything to call it...

Why I don't want a textfield in the cell: Because I think it is more smart/elegant to have the tableview cell activate the keyboard. I have seen this in other apps and I can't figure out how it is done.

Any help on this matter is much appreciated. I am completely new to programming, am using Swift (so have no clue Obj-C or the like).

Thank you!

Answer Source

Well after a lot of discussions around other websites, it is a shame to say it but what I wanted was actually impossible (like stated by Duncan). For some reason I thought that in programming that word did not exist, but alas it is there. Well, the way that I did work around this limitation was as replied here in the comments as well as from the resource materials I already read:

I have 2 views:

  1. tableView - this will have the list of items that I would like to edit a value. Has multiple labels where one of them would be edited by the user.
  2. keyboardView - custom keyboard that would allow user input.

For the keyboard I used the delegate method as described in "A Swift example of Custom Views for Data Input". This worked perfectly and would send the data over to the tableView under the keyWasTapped function.

Next was the tableView. I had 3 labels in the custom cell, where one was called valueLabel. I had to add a textField to my storyboard hidden behind the tableview with which the user will interact and in the didselectrow I included the command to summon the keyboard:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

From there I would grab the text from the textfield and update the UILabels in my custom cell. At least this way I can select a cell and not the textfield. So considering that the answer that would fit what I wanted is combination of the replies, I thought it would be best to say it here.

Thanks to Sandeep and Larme for their time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download