简体   繁体   中英

Cocoa disabling a NSTextField

Ok, I am working on a Cocoa app and I cannot get the text field to disable when the "Default Source" button is clicked. The cursor by default is in this text field when the program starts. When I click the default source button, the text field is not disabled until I manually click on another field and thus remove the cursor from the source text field. How do I make the text field disable immediately even though the cursor is there? Even if the cursor isn't there, the text field won't disable until I move the cursor there, and then back to another field.

I don't yet have 10 reputation... here is the link to the picture: http://i.stack.imgur.com/Bu0OG.png

Currently, this is the only line of code that is in the function that is called when you click "default source":

sourcePath.enabled = NO;

Try checking if your on the main thread before disabling by:

NSLog(@"is main thread: %d", [NSThread isMainThread]);

If your not, then you can:

dispatch_async(dispatch_get_main_queue(), ^{
    sourcePath.enabled = NO;
});

This code may be a little inaccurate as my background comes from iOS...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM