Pergunta

I'm doing some UIView animation stuff using

[UIView beginAnimations:nil context:nil];
// ... Animation configuration ...
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationEnded:finished:context:)];
[UIView commitAnimations];

Regarding the following question: Apple rejected app because of animationDidStop:finished:context: is a non-public api

I implemented my own method as the "setAnimationDidStopSelector".

My question is regarding the context:(void *)context parameter. Apple defines it as follow :

Additional application-supplied information that is passed to the animation delegate messages—the selectors set using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods.

I'm wondering what king of thing can be passed in as a context. I'm relatively new to Objective-C and C programming and a bit lost with the void* type.

Can we pass in any sort of argument, objects, NSDictionnary, NSString, etc.

Thanks

Foi útil?

Solução

void * is a pointer to anything. You can pass a pointer to any object or to other stuff such as a struct or a Core Foundation opaque type. To get rid of the compiler warning, cast the pointer to void *:

... context:(void *)myDictionary];

Be aware that the method has no idea what context contains and thus will not retain it or otherwise care for correct memory managemnet. You have to ensure that the thing you pass to context still exists when the animation delegate methods are called.

Outras dicas

context:(void *)myDictionary];

When calling this method and trying to pass

(void *)[NSNumber numberWithInt:5] - 

xCode proposes to make some _bridge because of invalid pointerCast from C to Objective-C ...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top