Results 1 to 2 of 2

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: [questions] SegmentedControl, NSString, Right button

  1. #1
    Default [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

  2. #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];
    }
    
    @end
    Last edited by NetMage; 2008-05-26 at 09:25 AM.
    Starlight Computer Wizardry
    Pocket-sized Development
    Follow me on twitter: @NetMage

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •