cessmestreet
cessmestreet

Reputation: 2318

UIViewAnimation setAnimationDidStopSelector Undeclared Selector, Will It Crash?

i would like to know what happens when you assign a selector to animationDidStopSelector that is not declared.

For example:

[UIView setAnimationDidStopSelector:@selector(doThis)];

i have this line of code. after calling the animation, it should call method, doThis, right? But if I didn't declare doThis or let's say I forgot to declare doThis, will my app crash? Or will UIView just ignore it? thanks.

Upvotes: 1

Views: 456

Answers (1)

matt
matt

Reputation: 535511

It will crash if the animation has a delegate (setAnimationDelegate:) and if that delegate does not implement doThis.

But it will not crash if the animation has no delegate, because there will be no one to send the message to. Nothing will happen.

Also, all of the above assumes you are using old-fashioned animation "blocks", constructing the animation with [UIView beginAnimations:nil context:nil] and ending them with [UIView commitAnimations]. If you use the modern form of animation construction with animateWithDuration:delay:options:animations:completion: and its friends, there is no delegate and no didStopSelector; your calls in that regard will be ignored, because the completion: handler fulfills that role.

Upvotes: 3

Related Questions