I'm seeing some very strange behavior with a UITextField
. I have a custom keyboard implemented, and it works great on iOS 7+. However, on iOS 6, when the following line is called (after doing a "backspace"), the text field's cursor vanishes, it isn't editable without resigning and becoming the first responder again, and the placeholder and real text overlap.
Here's the relevant code for my "backspace" function:
//Get the position of the cursor
UITextPosition *selStartPos = self.textBeingEdited.selectedTextRange.start;
int start = (int)[self.textBeingEdited offsetFromPosition:self.textBeingEdited.beginningOfDocument toPosition:selStartPos];
//Make sure the cursor isn't at the front of the document
if (start > 0) {
//Remove the character before the cursor
self.textBeingEdited.text = [NSString stringWithFormat:@"%@%@", [self.textBeingEdited.text substringToIndex:start - 1], [self.textBeingEdited.text substringFromIndex:start]];
//Move the cursor back 1 (by default it'll go to the end of the string for some reason)
[self.textBeingEdited setSelectedTextRange:[self.textBeingEdited textRangeFromPosition:[self.textBeingEdited positionFromPosition:selStartPos offset:-1] toPosition:[self.textBeingEdited positionFromPosition:selStartPos offset:-1]]];
//^This line is causing the issue
}
And here's what I'm seeing on iOS 6:
Anyone have any insights on this? Thanks!
EDIT
This appears to be happening for every nonzero value being set as the offset
.