开发者

userinfo in NSTimer iOS4

开发者 https://www.devze.com 2023-02-10 09:07 出处:网络
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));

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消