Vikr
Vikr

Reputation: 121

Check If a method Has Been Called and Do Not Call It Again

In touchesBegan I call a method [self animateWindow]; when I touch a UILabel. It animates and brings the window from top. When I touch that UILabel again, I don't want that method [self animateWindow]; to be called again because it animates and brings the window again which is already being displayed. How do I do this? Any help? I tried searching all over, couldn't find the exact answer.

Upvotes: 0

Views: 584

Answers (1)

Wain
Wain

Reputation: 119041

Just create an instance variable which is a BOOL as use it as a flag:

@property (assign, monatomic) BOOL hasAnimated;

- (void) touchesBegan...
{
    if (!self.hasAnimated) {
        [self animateWindow];
        self.hasAnimated = YES;
    }
}

Based on your expanded description in the comments, you're going to need to add some more logic which checks which label is actually being touch. A better solution may be to use gesture recognisers on each of the labels. Then you have direct access to the view of the gesture recognizer to check which label it was (perhaps using the tag) and you can add and remove gestures depending on what state you're in (only some labels should respond to touches and they should show or hide).

Upvotes: 3

Related Questions