borrrden
borrrden

Reputation: 33421

Disabled button still calls target

I have a system setup in my application where a user can pinch views to expand them to full screen (like Flipboard). However, when I do so, I want to disable some buttons that are visible in both modes. Normally it works fine but it fails in the following edge case:

1) Push button in non-zoomed mode (don't release)

2) Pinch view to enlarge, and wait for it to finish animating. The button then gets its userInteractionEnabled set to NO.

3) Release button, and the target function is called anyway. I put a breakpoint in the target function and used lldb to check the button and userInteractionEnabled was indeed set to NO.

Am I wrong in expecting that a button that is disabled should not fire its target? Should I check this in the target function?

Here is the function that actually disables the buttons, just in case you want to see (edit: there appears to be some confusion. There is nothing going wrong with the below code, I just included it to be thorough.)

//The function that disables the buttons
- (void)disableButtons:(SO2MenuButtons)buttons
{
    UIView *view = nil;
    if(buttons & SO2Mokuji)
    {
        view = [self.view viewWithTag:151];
        view.alpha = 0.5;
        view.userInteractionEnabled = NO;
    }
    if(buttons & SO2NoteView)
    {
        view = [self.view viewWithTag:152];
        view.alpha = 0.5;
        view.userInteractionEnabled = NO;
    }
    //etc, etc...
}

UPDATE:

I changed the above to this with the same result

- (void)disableButtons:(SO2MenuButtons)buttons
{
    UIButton *view = nil;
    if(buttons & SO2Mokuji)
    {
        view = (UIButton *)[self.view viewWithTag:151];
        view.enabled = NO;
    }
    if(buttons & SO2NoteView)
    {
        view = (UIButton *)[self.view viewWithTag:152];
        view.enabled = NO;
    }
    //etc, etc...
}

EDIT It seems I didn't clearly convey what the problem is, so I threw together a simple project that demonstrates the problem. You can download it here (Depending on when you read this message, the previous link may have expired). The problem is that the button is still firing its target method AFTER it has been disabled. After looking at what the above page looks like I apologize for using filedropper...I don't know what the popular way to share projects is these days >_<. Don't click on the big green download button, click on the one that says "Download this file"

Upvotes: 2

Views: 468

Answers (2)

borrrden
borrrden

Reputation: 33421

I found a way around this by setting exclusiveTouch to YES on those buttons. That way the user cannot pinch the views while holding the button. Of course, this doesn't really address the original issue so I won't accept this answer for now. If no one posts an answer for a while I will accept this one though.

Upvotes: 1

Steve
Steve

Reputation: 1840

It looks as if you are using the bitwise AND operator &, while what you want is the logical AND operator &&.

Upvotes: 1

Related Questions