0

Goal

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!

Community
  • 1
  • 1
TVDN
  • 305
  • 2
  • 11
  • 2
    I don't understand why you don't want a UITextField (no "white background, no border, etc.), and just "update the label", because you can customize the UITextField to make it look like a "label". In `didSelectRowAtIndexPath:`, just do `[theCellTextField becomesFirstResponder]` (or something like that) – Larme Jun 10 '16 at 13:09
  • A label is not editable. It won't show the keyboard. What you are trying to do is not possible. You want a text field, not a label. – Duncan C Jun 10 '16 at 13:43
  • Thank you Larme and Duncan, so I guess there is no way to call up a separate view from selecting a cell? A view that does not cover the entire window and can have anything in it like buttons and textfields? – TVDN Jun 10 '16 at 14:29

2 Answers2

1

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) {
        textField.becomeFirstResponder()
}

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.

TVDN
  • 305
  • 2
  • 11
0

TVDN,

Have a textField in cell not the label :) Create a custom cell create an IBOutlet to that class ffrom textField in cellForRowAtIndexPath

let tableCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! myCell
tableCell.yourTextField.resignFirstResponder()

and in didSelectRowAtIndexPath

let tableCell = self.tableView.cellForRowAtIndexPath(indexPath)
self.tableView.dequeueReusableCellWithIdentifier("cell") as! myCell
    tableCell.yourTextField.becomeFirstResponder()
Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
  • Hello Sandeep, thank you for the quick reply! I will definitely use this in my app, however, I would like to have the textfield with the keyboard. I guess the question is: how could I call on a view (that does not cover the entire window) when I select a cell in my tableview. This view can be anything, hence, I can also make a keyboard there... maybe I am just asking the wrong question here...? – TVDN Jun 10 '16 at 17:31