-
05-25-2008, 08:03 AM #1
[questions] SegmentedControl, NSString, Right button
I am using toolchain to develop an application, but currently I've hit some obstacles. I have several questions and hope you guys can give me some pointers:
1) How to determine if the user has selected a segment in a UISegmentedControl? The selectedSegment method will give segmentation fault at run time if I don't select any segment, and apparently there is not an isSelected method or something similar in the UISegmentedControl.h
2) I want to make sure that my string only contains digits and alphabets. For now my only solution is to do a "find string within string" operation for all special characters I can think of, but it surely is not the most elegant solution out there. Anyone has a better idea? Is there a way to disable special characters in the keyboard, or to trim them all off my string?
3) How to make the rightButton beside a UITextField to appear? I can make the clear button to appear by calling setClearButtonStyle, but setRightButtonStyle doesn't work, and setRightButton doesn't seem to exist.
Thank you
-
05-26-2008, 01:21 AM #2
For #1, this seems to imply you can use setDelegate: and get a segmentedControl:selectedSegmentChanged: message:
#91844 - Pastie
For #2, you could filter strings with a help message like this:
Code:@implementation NSString (SCW) - (NSString*) stringWithCharactersInSet: (NSCharacterSet*)aSet { NSScanner *sc = [NSScanner scannerWithString: self]; NSMutableString *ans = [NSMutableString stringWithCapacity: (int)([self length]*0.9)]; while (![sc isAtEnd]) { NSString *work = @""; if ([sc scanCharactersFromSet: aSet intoString: &work]) [ans appendString: work]; [sc scanUpToCharactersFromSet: aSet intoString: NULL]; } return [NSString stringWithString: ans]; } @endLast edited by NetMage; 05-26-2008 at 01:25 AM.



LinkBack URL
About LinkBacks
Reply With Quote