ios - Responding to DELETE on UIKeyboardTypeDecimalPad -
this thing driving me crazy. how repond user pressing delete key on numeric keypad? can't find delegate method , see empty string when shouldchangecharactersinrange() called.
thanks!
i figured out...
- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { if ([string length] == 0) return yes; nscharacterset *nonnumberset = [[nscharacterset decimaldigitcharacterset] invertedset]; string = [[string componentsseparatedbycharactersinset:nonnumberset] componentsjoinedbystring:@""]; textfield.text = [textfield.text stringbyreplacingcharactersinrange:range withstring:string]; return no;
}
Comments
Post a Comment