Reputation: 45
I'm writing an application that receives OSC messages. Here's a screenshot.
When I put the highlighted code in receivedOSCMessage method (which is called each time a message is received), the text field does not show the updated value of my_textfield.text, even though it does print the correct value in console. However, if I put it in ViewDidLoad, it works just fine. What might be causing that?
Edit: receivedOSCMessage is a delegate method.
Here are the contents of OSCMViewController.h:
#import <UIKit/UIKit.h>
@interface OSCMViewController : UIViewController
@property (retain, nonatomic) IBOutlet UITextField *my_textfield;
@end
Edit2: text field created in nib.
Messages are sent manually through a separate app.
Upvotes: 2
Views: 202
Reputation: 62676
Looks like the method is firing, and that the content of the message has a float that is successfully being represented as a string. You've also indicated that you can see the content of the text field when setting it's value in viewDidLoad
.
That's strong evidence that the receivedMessage method is firing before the view is ready. To confirm, add a breakpoint in both viewDidLoad
and in receivedMessage
. My guess is that you'll see the receivedMessage
breakpoint hit first.
The other possibility is that the message receiving component is sending the delegate message off the main thread, and your UI updates are being missed that way. Try, in the receivedOSCMessage method to wrap your code in a main thread block like this...
dispatch_async( dispatch_get_main_queue(), ^{
// do the ui work here
my_textfield.text = dat_string;
});
Upvotes: 1