When are selectionWillChange: and selectionDidChange: called? - ios

I am developing custom keyboard extension in iOS, and I'm wondering when the two UITextInputDelegate methods (selectionWillChange: and selectionDidChange:) called? Has someone tried to implement these two methods and made them work?

According to this
selection did change is called when the user takes the current highlighted text and replaces the whole thing or part of it. The selection will change is what it is going to change into before the did change event is fired.

Related

iOS 10 notification extension: can I change the action button text?

I've been playing around a little with the UNNotificationContentExtension framework to display a custom view inside a notification. So far, so good - got it rendering, and then altering content when a user taps on an action button.
But the one thing I don't seem to be able to do is change the text in the action buttons - not necessarily surprising given that it is defined in a UNNotificationAction I have to declare beforehand, but I'm wondering if anyone has had any luck in finding a way to change the button text?

iOS 8 Keyboard Extension Detecting first responder change

I'm writing a keyboard extension for iOS (hence overriding UIInputViewController) and I'm trying to figure out how to detect when the first responder changes. Is this even possible?
My motivation is that when the user selects a different text input field (while the keyboard is active) the style of the keyboard might need to change to suit the attributes of that input. This can happen when there are several text fields displayed on a UI and the user first selects one (causing the keyboard to be initialized) then the user selects another with different attributes (keyboard doesn't know it).
I've looked through the methods exposed by UIInputViewController and the delegates it implements but nothing I've seen really fits the bill. The closest thing I've found is selectionDidChange on UITextInputDelegate.
I found the best way to get this information is to override the UITextInputDelegate textDidChange method (UIInputViewController implements UITextInputDelegate). It turns out that textDidChange is called whenever the user switches the input text field (first responder), or when the text changes for some reason (luckily not when it is your keyboard that initiated the change).
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
That should tell you when it expects to become firstResponder. A couple things to keep in mind;
*This will only be called when a UITextFied is the thing becoming firstResponder. If some other object decides to, this won't be called. It'll probably call the method below.
-(BOOL)becomeFirstResponder
*Your class must conform to the UITextFieldDelegate and all of your UITextFields must set their delegates to self. Without that they won't call shouldBeginEditing on your class.

How do I get the currently focused element when using VoiceOver on iOS?

I have a table with cells that the user may swipe to mark them "completed". I am trying to make this accessible using VoiceOver by implementing the accessbilityScroll method.
This works fine, but I can't figure out what cell has focus when the user scrolls.
I only find information on how to change focus.
Hehe, Ok. I just figured it out.
There is a protocol for this. Its called UIAccessibilityFocus
Method: accessibilityElementDidBecomeFocused:
Well, I will leave this question here to any one else that is out there struggling with this.
Your program can also tell where VoiceOver’s “focus” (the object that it’s dealing with) is, and when “focus” enters or leaves any given object.
For Focus Information click here
– accessibilityElementDidBecomeFocused
– accessibilityElementDidLoseFocus
– accessibilityElementIsFocused
As of iOS9, you can use
UIAccessibilityFocusedElement(UIAccessibilityNotificationVoiceOverIdentifier)
https://developer.apple.com/documentation/uikit/1615119-uiaccessibilityfocusedelement

How can I decide if switch view value was changed by user interaction or by code in IOS?

I have a switch view on my UI and I'd like to handle the event when its value is changed. To perform this I've made an IBAction method to handle value changed event. So far so good.
My problem is I can't decide if change was performed by
- code (it may happen in my app)
- user interaction
How can I decide if it was changed by a user interaction or by code?
Is there a specific method that changes the switch value when it's done by code only? If so, maybe you could use that method to set a boolean/flag to check against when you need to decide/handle the event.
In Apple ScrollView / ScrollPages Example they have a simmilar situation:
They have to decide whether an event was self(=code) triggered, or by the user.
They simply set a variable (before programatically calling) to distinguish between this two situations.

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