0

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
ctfd
  • 338
  • 3
  • 14
  • you want to append to the text field? – Bryan Chen Apr 23 '14 at 02:09
  • 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) – modusCell Apr 23 '14 at 02:13
  • @BryanChen Yes, appending it would be fine, although I'm not exactly sure how to accomplish that. – ctfd Apr 23 '14 at 02:18
  • @mohacs, Ah - yes that is what I was thinking. How do I put `sleep(1)`? although I might append it as Bryan mentioned. – ctfd Apr 23 '14 at 02:19
  • just add sleep(1); between lines. – modusCell Apr 23 '14 at 02:20

2 Answers2

0

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

Bryan Chen
  • 45,816
  • 18
  • 112
  • 143
-1

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