How to show keyboard programmatically - ios

I have UITableView where each cell consists of two UILabel, I want to show up keyboard when the cell is selected? Is it possible with UILabels?

If you just want to pop up a keyboard, you can add a tiny invisible (transparent 1x1 with transparent text) UITextField anywhere in any visible view and make this text field first responder to pop up a keyboard. Then you can redirect the input text to any of the two labels (or somewhere else) using the text field delegates to capture the input.

Yes, the label has to conform to the UIKeyInput protocol. Note that this is an either-or proposition. If the label conforms to UIKeyInput, then when it becomes first responder, the keyboard will be displayed, whether you want it or not.

I'm not sure how you mean this exactly since it is obviously not possible to edit two textfields for labels at the same time. Hence the following assumes you want to show the text in your cell using UILabel, but want to be able to edit the cell's text.
You can't directly use the keyboard to edit UILabels. The easiest solution is to directly use UITextFields instead of the UILabels.
An alternative is to have both a UITextField and UILabel in the cell. Then show the textfield (by settings itsß hidden property toYES`) when the cell is selected and hide the label. When editing is finished, do the reverse (i.e. showing labels, hiding textfields).
To show the keyboard directly after selecting the cell you can call [someTextField becomeFirstResponder];. To check if the user is done editing (and e.g. tapped the return key), you can set the delegate of the UITextField.

Related

UITextView check whether text field is empty or not in Objective-C

i have UITextView which is inside the tableview cell, and when i click on the "NO" option , the cell will expand , i need to pass the both text which is entered in the textview and image which is uploaded here,
But the problem is am not able to validate the textview, whether it is empty or not,
i should check whether it is empty or not, and if it is empty is need to alert the message.
Set the table view cell containing your text as a custom table view cell. When you do that, you can connect your UITextView to an outlet.
Once you do that, it's easy to check by simply looking at the length of the .text property for that outlet.
e.g. something like:
(for Swift):
if myTextView.text.characters.count > 0
{
// there is something in here
}

iOS UITextView hardly gets Focus

I have a TableView with some Cell's that contain a UITextField and some with a UITextView.
While presenting a UITableViewController i'm getting a strange behavior. The TextView has a property called "Selectable":
If I leave this checked, the last Cell that contains a TextView becomes automatically focused. And Of Course the keyboard will popup and hide content.
If I don't check it, it won't become focused when the view loads - that's what I want - but no touches in the Cell's TextView are not recognized.
So any idea why:
The Selectable property prevents any touches?
Whats the difference then between Selectable & Editable?
Any Solutions for my dilemma?
selectable means that data detectors (dates, addresses, etc., in accordance with the dataDetectorTypes property setting) act as links.
editable means that the user can type, select, copy, and paste the text itself.
Also, don't trust the Interface Builder (nib editor) interface on these properties. Set them in code.

allow user to tap label and then tap buttons to edit label.text?

So what I have right now i table with multiple cells. Each cell has two UIlabels. Underneath the table are a bunch of buttons with different int values. I want to allow the user to tap on a label and then tap on the buttons to change the text of the label to whatever buttons they press. Eg if they press buttons, "1","2","3" the label will display 6.
I think i managed to figure out how to find out which label has been touched, but I'm stuck afterwards as i can't figure out how to get the button pressing part to work. Any ideas? thanks in advance!
To know which UILabel has been touched add a tap gesture to each label which triggers an action. In that actions store which label has been touched in e.g. a property.
For the buttons, just connect them to action methods (could also be a single one), inside these methods do your calculation and updated the label indicated by the property described above.

Dealing with keyboard and tableviewcell

The layout for one of my View Controllers is such: I have a scroll view embedded inside my VC. Inside my scroll view, I have a table view that consists of 5 cell. The first 3 cells consist of a textfield thats pulls its text from a dictionary and this changes depending on certain situations. These textfields are editable and so tapping on them brings up the keyboard, the issue however is that I would like my view to scroll when I tap on the text field because right now they keyboard hides the the third editable text field. Another issue is that at the moment, clicking outside teh table view doesnt cause the keyboard to be dismissed and so the only way of dismissing the keyboard is tapping on the return key. What I would like to happen is that when I tap on either one of the 3 editable fields, the scroll view ought to scroll up a certain number that I define (this is so that I can define how much to scroll depending on which row is currently selected). One of the issues I'm facing is that I can't directly reference these textfields in my VC since they're all created through one prototype cell. My thinking was that I could create a dictionary with the 3 textfields as keys and then the scrollview y coordinates as values and then use that. However , I wasn't sure how to do this in my situation (with the prototype cells). Would really appreciate if someone could show me some sample code on how to do this.
You can reference your text fields by calling cellForRowAtIndexPath: to get the UITableViewCell, then calling viewWithTag: to get your UITextField. Just assign the text fields a tag number. Also, set the text field's delegate to be your view controller so that you can respond to a user tapping to edit text.

Make UITextField inside a table view visible scrolling

I have a UITableViewController, a bunch of sections and rows, and for each row I added a UITextField as a subview, right aligned in the row itself.
If the users taps on the row, I locally save the indexPath, make the corresponding text field become the first responder and finally, when the keyboard appears, I make the table view scroll so that the row remains visible.
I am facing the problem to obtain the same behaviour when the user taps the text field instead. In this case the didSelectRowAtIndexPath: method isn't called, so I do not know how to tell the table view to scroll to make sure that the "selected" row is still visible.
Probably the whole process is not correct. Do you know a way to solve it?
Thanks a lot!
I'm not absolutely sure about this, but...
Set the userInteractionEnabled property of the UITextField to NO. This way, the touch goes "through" the control, tapping the UITableViewCell. When didSelectRowAtIndexPath: is called, set the userInteractionEnabled property of the UITextField to YES. When the editing is complete, change it back to NO.

Resources