0
votes

I have an NSTextField that displays status info as needed. It works, sort of... The problem is that it only displays the last very last updatedString and none before it in the NSTextField. When checking NSLog all of the strings appear. Is NSTextFieldunable to process it quick enough or maybe it's displaying so fast the human eye can't see it?

example:

- (void)update {

            NSString* updatedString = @"Update - 1";
            [self updateTextField:updatedString];
            // do other stuff
            updatedString = @"Update - 2";
            [self updateTextField:updatedString];
            // do other stuff
            updatedString = @"Update - 3";
            [self updateTextField:updatedString];
            // do other stuff
            updatedString = @"Update - 4";
            [self updateTextField:updatedString];
}

- (void)updateTextField: (NSString *)updatedString  {

        [TextFieldValue setStringValue:[NSString stringWithFormat:@"%@", updatedString]];   
}

NSTextField shows (once):

Update - 4

NSLog shows:

Update - 1
Update - 2
Update - 3
Update - 4
2
you want to append to the text field? - Bryan Chen
you can't see it is updating with human eyes it happens almost instant, if you are processing something between updates you can put runloop then it show one by one. as i understand doSomething parts are happening so fast as well, if you just want to fake it put sleep between. sleep(1) - modus
@BryanChen Yes, appending it would be fine, although I'm not exactly sure how to accomplish that. - ctfd
@mohacs, Ah - yes that is what I was thinking. How do I put sleep(1)? although I might append it as Bryan mentioned. - ctfd
just add sleep(1); between lines. - modus

2 Answers

0
votes

you can append the string in text field by

[TextFieldValue setStringValue:[NSString stringWithFormat:@"%@%@", [TextFieldValue stringValue], updatedString]];

if you want it to sleep, use

 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1/*seconds*/, NO);

instead of sleep so your app won't be freezed

-1
votes

Had the same problem, it was fixed by putting [CATransaction flush]; and a usleep after the NSTextField setstringValue.