Dissappearing textField string value

  • Good people,

    This one really has me stumped. Perhaps someone can help me out.

    In my program is the code...

    NSAttributedString *theAttributedString = [[NSAttributedString alloc ]
                                                initWithString: possibleString
                           attributes: theAttributes];
    PRINT_APPEND(@"\n%d (%d)...\n%@",
        [theAttributedString retainCount],
        [theAttributedString length],
        theAttributedString);
    [theSudokuTextField setAttributedStringValue: theAttributedString];
    NSString *s = [theSudokuTextField stringValue];
    assert([s length] != 0);

    PRINT_APPEND looks like this

    #define PRINT_APPEND(format, ...) [self printAppend: [NSString stringWithFormat: format, ##__VA_ARGS__]]

    printAppend looks like this

    - (void) printAppend: (NSString *) theNSString {
    printf("%s", [theNSString UTF8String]);
    }

    This is what appears on the debug console

    1 (29)...
        2
        5
      7  8  {
        NSFont = "\"BaskOldFace 9.00 pt. P [] (0x3687e20) fobj=0x511bf0, spc=2.25\"";
    }Assertion failed: ([s length] != 0), function -[Controller updatePossibilitiesDisplay:], file /Users/Charlie/SudokuX III/Controller.m, line 1143.

    What could possibly make the stringValue disappear like this?

    Charlie Dickman
    <3tothe4th...>
  • I'm confused. What's the method stringValue on theSudokuTextField? That's one of your methods right as stringValue is a method on NSNumber AFAIK. What does it do?

    You're setting the attributedStringValue and the getting the stringValue, in what way are they related?

    On May 14, 2012, at 10:36 AM, Charlie Dickman wrote:

    > Good people,
    >
    > This one really has me stumped. Perhaps someone can help me out.
    >
    > In my program is the code...
    >
    > NSAttributedString *theAttributedString = [[NSAttributedString alloc ]
    > initWithString: possibleString
    > attributes: theAttributes];
    > PRINT_APPEND(@"\n%d (%d)...\n%@",
    > [theAttributedString retainCount],
    > [theAttributedString length],
    > theAttributedString);
    > [theSudokuTextField setAttributedStringValue: theAttributedString];
    > NSString *s = [theSudokuTextField stringValue];
    > assert([s length] != 0);
    >
    > PRINT_APPEND looks like this
    >
    > #define PRINT_APPEND(format, ...) [self printAppend: [NSString stringWithFormat: format, ##__VA_ARGS__]]
    >
    > printAppend looks like this
    >
    > - (void) printAppend: (NSString *) theNSString {
    > printf("%s", [theNSString UTF8String]);
    > }
    >
    > This is what appears on the debug console
    >
    > 1 (29)...
    > 2
    > 5
    > 7  8  {
    > NSFont = "\"BaskOldFace 9.00 pt. P [] (0x3687e20) fobj=0x511bf0, spc=2.25\"";
    > }Assertion failed: ([s length] != 0), function -[Controller updatePossibilitiesDisplay:], file /Users/Charlie/SudokuX III/Controller.m, line 1143.
    >
    > What could possibly make the stringValue disappear like this?
    >
    > Charlie Dickman
    > <3tothe4th...>
  • On 14/05/2012, at 3:01 PM, Roland King wrote:

    > I'm confused. What's the method stringValue on theSudokuTextField? That's one of your methods right as stringValue is a method on NSNumber AFAIK. What does it do?
    >
    > You're setting the attributedStringValue and the getting the stringValue, in what way are they related?

    Well, they are related, but perhaps you stumbled on the answer anyway.

    NSTextField inherits -stringValue from NSControl, so that's no problem.

    But, if you use -setAttributedStringValue:, you should use -attributedStringValue to retrieve it. Internally, I do not believe that NSControl automatically reduces an attributed string to an ordinary string, but maintains them as totally separate values. If there is an attributed string to display, it will take that over a plain string, but it does not provide any conversion between them.

    --Graham
previous month may 2012 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today