I am setting up a UITextView with a tap gesture recognizer so that I can do various things after the textView is tapped. For one I want the text view to be the "selected" view after it is tapped, like so:
selectedTextView = (UITextView *)recognizer.view;
It works, except that after the text view goes into text edit mode, reveling the keyboard and allowing text editing, thereafter my custom tap gesture recognizer no longer works.
Any way around this?
You might just need to return YES for -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer for your recognizer.
It would appear that when the UITextView becomes the firstResponder (keyboard appears), that Apple's code removes all gesture recognizers from that UIView. You can add your recognizers again in UITextViewDelegate's –textViewDidBeginEditing:. It also appears to remove recognizers when resigning firstResponder so you'll have to also add it in -textViewDidEndEnding:
The same is true for UITextFields.
Related
My iPhone app (based on the "Single View Application" of Xcode) has a UITextView (say: myTextView) that I want the user to be able to edit. I was setting it to editable, and all was working fine (I didn't even have to invoke becomeFirstResponder).
Then I moved it in another UIWindow (say: newWindow) (on top of the main/root/key one that is called self.window (of the Single View App.)).
But now, when I click on the UITextView, the keyboard does not show.
Everything works if I do this:
[myTextView setEditable:YES];
[myTextView becomeFirstResponder]; // ugly...and I do not need it, but I added it just in case...
[self.window addSubview:newWindow];
but the keyboard is shown immediately (since I set becomeFirstResponder) that is not nice.
But if I remove the becomeFirstResponder line, the keyboard does not show at all!
If I move the [self.window addSubview:newWindow] line above, then no matter what I do, the keyboard is not activated...
[self.window addSubview:newWindow]; // this is how it should be... but,
[myTextView setEditable:YES];
[myTextView becomeFirstResponder]; // even when I enter this, it's not working :-(
I tried [newWindow makeKeyAndVisible] nothing. I tried to add a touch delegate and detect a touch (or a gesture) on the UITextView, they work (I get the NSLog message I included), but again, no keyboard. I even tried to add another field (of the main window) on top of newWindow (so as to have a main window element on top), still no luck...
What am I missing?
You shouldn't add a UIWindow as a subview. Instead, windows are shown either by calling -[UIWindow makeKeyAndVisible], or -[UIWindow setHidden:NO] if you don't want it to receive key events.
It's rare that you need to use multiple windows though. Just using a normal UIView add adding that as a subview will do in many cases.
EDIT: I had a confusing remark before about "assigning to a screen". UIWindow has a property "screen", which you can assign to if you want to display the window on another screen than the main screen. You don't need to care about that for your use case, though.
I have an app, one activity is a form with multiple fields. In landscape mode when clicking into the first field the fullscreen IME kicks in, with a "Next" button.
The "Next" button, however, does not respond at all. No errors are thrown, nothing logged related to this - it just doesn't move to the next (of about 12) text fields.
Same (lack of) behavior when other fields are selected on the form and text entered/not entered in landscape view - non-responsive next button.
The final EditText field correctly shows a "Done" button...which is also unresponsive.
I've had no luck searching forums and Googling this, and nothing I've been able to find related to the IME has helped to this point.
One option, of course, is to force portrait mode (which works fine), but I would rather avoid that klunky workaround.
Any suggestions, references to code/examples related to this would be greatly appreciated.
Resolved using android:imeOptions="actionDone" in the EditText layout if the next element is not an EditText view, or if at the end of the form. All other EditText layouts added android:imeOptions="actionNext".
This allows a full-screen IME in landscape view to navigate from one EditText to the next, form an EditText out of the IME if the next field is a button or spinner (any non-EditText field), and exit the full-screen IME after the last form field.
I have a table listing some strings, and what I want is when I tap the add button on the navigation bar, a keyboard with a textField would jump up, so I can input a string in the textField, then when I tap the return key, the keyboard disappear as well as the textField, and the new string is added to the table.
I already make up a nib file with a toolBar containing a textField, and I just failed to go on.
How can I implement this idea? Use the inputAccessoryView? If so, that means the inputAccessoryView of the textField which belongs to the toolBar is gonna be the toolBar itself!
This seem kind of weird and I have not been able to make it work till now.
Or is there another way for this idea?
Thanks a lot!
I've solved the problems by using notification instead of inputAccessoryView.
There is a sample code in XCode called "KeyboardAccessory", and it gives a good example about using keyboard notifications!
Or custom a view with a tab, and set it as the textField's inputAccessoryView, that would also work!
Is it possible to change the "Back" button text in a NavigationItem? At present, the caption of the back button assumes the title of the previous layer in the navigation stack, which is expected.
However, the NavigationItem's LeftBarButtonItem can be changed using code such as this:
UIBarButtonItem backButton = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, null);
myNewView.NavigationItem.SetLeftBarButtonItem(backButton, true);
This works and the back button is displayed as expected, but the button is a square and does not navigate back to the previous layer as expected. I'm guessing that the correct event needs to be assigned to it, but I have no idea what it should be.
How would one go about ensuring that the new UIBarButtonItem has the correct event and arrow shape?
Note: I have also tried re-using the `LeftBarButtonItem' as suggested in this SO question, but I still don't know how to customize the button caption. I am probably just missing the obvious.
Thanks!
Set the title on the previous viewcontrollers navigationitem. I answered this before and will look up the link.
Ah, yes: Separate title in NavigationBar and navigation buttons
I have attached a toolbar with a UITextField and UIButton to the keyboard when it becomes the first responder via the user taping inside the textfield
textField.inputAccessoryView = theToolbar;
Problem is, the toolbar disappears when the keyboard is dismissed, thus preventing any further input.
Any ideas on how to make the toolbar go back to the bottom of the screen rather than off it completely?
I'm thinking a delegate method might help but Im really not too sure. It seems once the inputAccessoryView always the inputAccessoryView :(
Cheers
The input accessory view is automatically dismissed with the input view (the keyboard, in this case). Generally you do not want to have an input accessory view in your view hierarchy. Instead, if you want your toolbar to scroll up when the keyboard is shown, you should follow the guidelines for Managing the Keyboard.
You could try using an additional toolbar that is offscreen as the inputAccessoryView, which could "fake" the appearance of what you are trying to do. Alternatively, have you tried adding the toolbar back to the bottom of the screen using
[self.view addSubview:theToolbar];
when the keyboard reaches the bottom of the screen? You can use keyboard notifications for this.