string/character comparison roadblock

5 views
Skip to first unread message

AppleMike

unread,
Nov 13, 2009, 3:11:36 AM11/13/09
to iPhone Application Development Auditors
I have the feeling this is going to be extraordinarily simple, but for
some reason the answer is avoiding me...

I'm trying to limit the status UITextField to 140 chars.
I can count to 140, then not allow any further character input just
fine.
However, it'd be handy to allow just backspace/delete to squeak by so
the user can backspace once they have crossed the 140-char limit.

My problem is...how the heck to compare the NSString given me by:
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range replacementString:
(NSString *)string
against the BS (unicode 0x0008) and DEL (unicode 0x007f) keys.

I've tried a number of NSString methods and casts to no avail.

AppleMike

unread,
Nov 13, 2009, 12:41:39 PM11/13/09
to iPhone Application Development Auditors
Aha...got it figured.
Instead of checking for char '\b' in string, I can just check the
NSRange sent back from
textField:shouldChangeCharactersInRange:replacementString:
If the delete key was pressed, range.length will == 1, otherwise it'll
be 0.
Reply all
Reply to author
Forward
0 new messages