Using tableView:didDeselectRowAtIndexPath: to edit a UITextField in a cell - ios

How would you use tableView:didDeselectRowAtIndexPath: to trigger textFieldShouldBeginEditing: ?
Or what other options do I have? I did consider having tableView:didDeselectRowAtIndexPath: trigger a UIAlertView (with textField) but it isn't aesthetically pleasing.

Your question is a little light on details: what's the user interface look like? What are you tying to accomplish?
To literally answer your question, you can just have didDeselectRowAtIndexPath implementation call the method textFieldShouldBeginEditing - however I don't believe that's what you're asking? What it sounds like you're asking is how you can get a touch event on a table view cell to pass into a UITextField so that editing begins.
That would make this a duplicate of other questions already asked here:
Having a UITextField in a UITableViewCell

Not sure how proper the practice is, but I have an app I use a textField that is 1x1 points and off screen. If I want to bring up the keyboard, I call
[self.myTextField becomeFirstResponder];
Then you can use the UITextFieldDelegate methods to control and update information being entered on the keyboard.
Then when the user is done, I call
[self.myTextField resignFirstResponder];
Of course this is assuming that you don't actually want to use a textField in your tableView.
Hope this helps.

Related

Is it possible to add a Done key to ALL keyboards in an app?

Is it possible to add a done or cancel key which dismisses a keyboard to all keyboards in an iOS app? There are several posts asking how to dismiss a keyboard via a cancel or done button, but the solutions are on a field by field basis.
Are there any solutions that add this functionality globally so the code wont need to be duplicated for each textfield/area in an application?
Like #silentBob says in his answer, the inputAccessoryView of a text field is the view that’s displayed immediately above the keyboard when the text field is the first responder. If you didn’t want to write an extension on UITextField to override the -inputAccessoryView method, you could also create a subclass of UITextField to do the same, which would make it easier to determine which method is going to be called. You could also have multiple subclasses of UITextField to customize which button(s) appear. If you have a text field in a storyboard, you can simply change the class to your custom subclass, so while you have to go through and make those changes, you don’t have to do it in code.
Yes, you can add an extension to UITextField class, which should add a UIToolbar with Done and Cancel actions as UITextField inputAccessoryView.
Well, In that case you have to customise the keyboard, built your own keyboard and do whatever you need to do with your key in the keyboard.

How to make UITextView register touches when it is currently first responder?

I need a way to know when a UITextView is touched while it is first responder. I have seen some threads about this but I have never figured out how to make it work. I'm assuming there must be a way? Any input would be much appreciated thanks!
rc
UITextField is a subclass of UIControl, so you can add yourself as listener for events using addTarget:action:forControlEvents:.

Detecting when a user is beginning to edit an UITextView

I am wondering if it is possible to detect if a user is beginning to edit a text view (so that I can make certain adjustments to the view). Would I have to detect for the keyboard instead?
Yes it is possible using UITextView's delegate. You can see documentation of the UITextViewDelegate protocol here.
There is a nice tutorial found here that will show you how to detect these interactions using the UITextViewDelegate protocol.
Take a look at UITextViewDelegate. Implement textView:shouldChangeTextInRange:replacementText: if you want to react while the user is typing or textViewDidChange: otherwise.
Edit: If you are only interested when the text fields becomes the first responder (i.e. the user sets the focus), use textViewDidBeginEditing.
Assign your textView's delegate in your xib file (or programmatically)
Use one of these:
- (BOOL)textViewDidBeginEditing:(UITextView *)textView {
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {

iOS keyboard won't dismiss after view dissappears

I have been looking for a similar questions but so far the answer doesn't fit my purposes. I have a UITableViewController inside A UINavigationController with custom UITableViewCells containing textfields inside. When I click on the textfields they become the firstResponders and when I click return they resign it. So far so good.
My problem is one of these cells is performs a Submit function. After this is done whenever I press the textfields the return button doesn't dismiss the keyboard anymore.
My question is, since I'm not releasing anything, why do these textfields stop listening to the resignfirstresponder message?
UPDATE: I finally got this working by setting an UITextfield ivar in the class, making it the first responder whenever the textfield begins editing in :
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField setTextColor:[UIColor blueColor]];
focusedTextField = textField;
}
And calling [focusedTextField endEditing:YES]; when i press the submit button. Just added this after seeing some answer in SO, but I can't remember the link, sorry.
Hope it helps.
If you have declared a method for return(let's say your textfiled is called textField) use this code in your method;
[textField setUserInteractionEnabled:NO];//but this may restric you if you need to use it again
But if you use standard return property of the keyboard it may be something related to Apple's restrictions

custom input view keyboard functionality

I wanted to ask a quick question just to make sure I am not missing anything simple before I implement a more difficult method. I need to create a custom keyboard for an iPhone application. This I have already done by creating a view with the buttons, using a custom input view and it displays exactly like it should. Now most of the buttons are standard numbers which need to update a UITextField in the screen that called the keyboard. Does anyone know a simple way to do this? I assume there has to be a built in function that the keyboard uses to send the information but I haven't been able to find any reference to it. Otherwise I will have to go the more difficult route. If anyone has a simple way to do this I would appreciate it. I haven't worked with custom keyboards before.
You won't be able to do it the same way that Apple does it, as their keyboard is basically an input device, globally.
I recommend you just append the data in your button press multiplex method. Here's an example:
NSString *appendThisText = #"subtitle";
self.myTextView.text=[NSString stringWithFormat:#"%#%#", self.myTextView.text, appendThisText];
Custom keyboards are simpler than you realise.
UITextField conforms to the UITextInput protocol. That's a bit of a red-herring because this protocol provides all the really complex stuff like selecting text and so on. But UITextInput itself conforms to UIKeyInput. This is your friend.
The key UIKeyInput methods are:
- (void)insertText:(NSString *)text;
- (void)deleteBackward;
Your keyboard class should have a delegate (which points to the textfield that the keyboard is operating on) and you simply call these methods to insert and delete text.

Resources