开发者

Cocoa app interface randomly "disconnecting" from program code

开发者 https://www.devze.com 2023-01-20 09:46 出处:网络
I have a multi-threaded Cocoa app that processes images. The program has a progress bar and some text showing how far along the process is. This all works great. However, sometimes the interface will

I have a multi-threaded Cocoa app that processes images. The program has a progress bar and some text showing how far along the process is. This all works great. However, sometimes the interface will just freeze up and everything will stop updating. The progress bar stops moving, and the text stops updating in the percentage counter. However, the actual process is still working! I have an NSBeep() that fires when the program is finished, and I still hear that even though the UI is no longer being updated. It's as though the UI just disconnects from the code.

Another weird problem is that sometimes the NSOpenPanel that opens when the user wants to choose a file will just be a white void. I declared the NSOpenPanel 开发者_如何学Python(I'm using [NSOpenPanel openPanel]) in the main thread, which helps (I tried retaining it at first, but that didn't work). I don't know if this is related, but any ideas would be appreciated!

I am using Xcode 3.1.1 (GCC 4.2) on Mac OS X 10.5.8.


You're trying to manipulate the UI from other threads. As stated in the docs, AppKit is generally not thread-safe and you should interact with your GUI on the main thread. See -performSelectorOnMainThread:withObject:waitUntilDone:.

0

精彩评论

暂无评论...
验证码 换一张
取 消