문제

I want to have a single method for all the buttons (and all their events) of a view. So far this is what I've got:

- (IBAction)uibuttonEvent:(id)idSender forEvent:(UIEvent*)uieventHandle
{
    if (idSender == [self uibuttonConnectInput]) {
        if ([uieventHandle type] == UIEventTypeTouches) {
            [[self uibuttonConnectInput] setTitle:@"did it!" forState:UIControlStateNormal];
        }

    } else if (idSender == [self uibuttonSomething]) {
        ...

    }
}

So now I can detect whether the event is a UIEventTypeTouches or not, but I want to check more specifically whether it is e.g. UIControlEventTouchUpInside - how can I do that?

도움이 되었습니까?

해결책

As discussed here the UIEvent that you get from UIButton doesn't give you any information about which UIControlEvent caused it. Either register separate methods for each event type (the recommended solution) or make your own subclass of UIControl and make it behave differently.

다른 팁

I think you have to give different tag for all that button.

- (IBAction)uibuttonEvent:(id)idSender {
    int iTag =  [sender tag];
}

You can identify which button was pressed.

All the best!!!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top