Search code examples
cappuccino

Disabling a view in cappuccino


How can I disable a CPView? (so that the user can't interact with it while it's still visible) It's useful for example when the user clicks on something that sends a request to the server and it should get disabled till the result comes back.


Solution

  • CPControls (as abstract subclass of CPView) contains a -setEnabled: method which most UI components inherit from. http://cappuccino.org/learn/documentation/interface_c_p_control.html#a68d3dc4f2d0a4fad8699fd5982cddc2d

    CPViews do not contain such a method, so in your CPView subclass you need to write your own method for enabling and disabling. Then override -mouseDown: and whatever else you need to (look at the docs for CPResponder for a complete list) and implement like so:

    - (void)mouseDown:(id)sender
    {
        if ([self isEnabled])
            [super mouseDown:sender];
    }