Reputation: 6051
every one i create custom keyboard and i have problem
iam using my keyboard as textview.inputView = myKeyboardView;
my keyboard buttons have this code :
NSMutableString *text = [textPad.text mutableCopy];
NSRange selectedRange = textPad.selectedRange;
[text replaceCharactersInRange:selectedRange withString:@"A"];
textPad.text = text;
[text release];
so the problem is when i want edit a word from middle of my sentence if i select a word and add some letters to that my button write only ONE Character and if i write some other letters that begin end of sentence ! what can i do to solve this problem ?
//EDIT//: PROBLEM SOLVED
Upvotes: 0
Views: 592
Reputation: 33592
My first guess is that you need to set selectedRange
. Also consider using convenience constructors rather than explicitly creating mutable copies — you only mutate it once so it's not likely to be any more efficient.
NSString *text = textPad.text;
NSRange selectedRange = textPad.selectedRange;
NSString *replacement = @"A";
text = [text stringByReplacingCharactersInRange:selectedRange withString:replacement];
selectedRange = (NSRange){selectedRange.location + replacement.length, 0};
textPad.text = text;
textPad.selectedRange = selectedRange;
Upvotes: 1