userinfo in NSTimer iOS4
I want to pass some data to the fire method.So I use the 'userInfo'
I did like this:
struct MyStruct* userinfo = malloc(sizeof(struct MyStruct));
userinfo->a = 1;
userinfo->开发者_如何学JAVA;b = 2;
NSTimer *myTimer = [NSTimer scheduledTimerWithInterval:0.05 target:self selector:@selector(myFireMethod:) userInfo:userinfo repeats:YES];
But the problem happened,the iOS app crashed when running the scheduledTimerWithInterval
method.
It must be something wrong with 'userinfo' .What's the probably mistake?
userInfo has to be Objective C object, cause it's retained during assignment.
If you want to pass C-struct you have to wrap it with NSValue:
NSValue* val = [NSValue valueWithPointer: your_struct_ptr];
精彩评论