Trouble making multiple updates to Textfields in method
I am trying to update a status textfield within the same method, before and after a numerical routine that takes 10-20 s to run. The update is not working, until after the numerical routine and then only takes the final values. Why won't it update prior to the numerical method call?
The NSLog entries work perfectly, but the textfield updates and button settings don't work until after the return from "calculateBrushDistribution"... any help much appreciated!
Brad
Code snippet:
NSLog(@"calculating solution...");
[calculateButton setEnabled:NO];
[programStatusField setStringValue:@"Calculating solution of non-linear system."];
[brush calculateBrushDistribution]; <-- numerical subroutine method
NSLog(@"solution found");
[saveButton setEnabled:YES];
[calculateButton setEnabled:YES];
[programStatusField setStringValue:@"Solution has been calculated."];
When you update a field from Cocoa, you're updating the value in the control. Until you allow the event loop to run I think the control will be unable to display the new value. So I think you'll have to update the field and start the calculation on another thread. When the calculation completes it can update the result field. You may also wish to provide the user with visual indicators of the background processing. For example deactive some controls and/or popup progress indicator. Of course the controls should be reactivated when the thread completes (or whatever makes sense in the context of your application).