Re: performSelector doesn't work for modal window
Re: performSelector doesn't work for modal window
- Subject: Re: performSelector doesn't work for modal window
- From: Ken Thomases <email@hidden>
- Date: Fri, 12 Mar 2010 20:25:36 -0600
On Mar 12, 2010, at 10:34 AM, Alexander Bokovikov wrote:
> Unfortunately NSButton click is called when button is pressed, but not when it is released.
This is incorrect. You can click in a button, hold, drag out of the button, and release, and the button won't perform its action. The action is performed when the mouse button is released, if the cursor is still within the button.
> Therefore any timeconsumming process, executed on the button click, will keep the button pressed.
You mean, the button will continue looking like it's depressed. This is intentional.
However, the problem is not the appearance of the button that should concern you. It's the fact that the GUI will remain unresponsive for the duration of the time-consuming task. Even if you put it off until after the button redraws itself without the highlight, the GUI will be unresponsive. In fact, in some ways, this is worse. Now, the GUI looks to the user like they can continue to use it, but that's a lie. At least when the button looks depressed, that's a visual clue to the user that the GUI won't be responsive.
You probably should either use asynchronous techniques for the time-consuming task or do it on a background thread. Either way, you still need to consider how to represent the ongoing work in the GUI. There's just no simple shortcut to get around doing the right thing. For example, should the user be permitted to click the button again while the time-consuming task is already going? If not, then you'll need to disable the button or switch the GUI so it's no longer present.
> To avoid it I've decided to use performSelector:withObject:afterDelay: message. This approach works OK for main window, but it doesn't work for a modal popup panel. More exactly, this message is sent only when modal window is closed and NSApplication is returned to the main messages loop.
>
> It looks like this is a fundamental Cocoa specifics, though I don't understand it. So, how to send a message to a modal window messages loop?
As noted by Paul Sanders, you can use -performSelector:withObject:afterDelay:inModes:. In trying to understand this issue, did you even read the documentation for -performSelector:withObject:afterDelay:? It's all described right there.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden