NSTimer iOS4 中的用户信息
我想将一些数据传递给 fire 方法。所以我使用了
这样的“userInfo”:
struct MyStruct* userinfo = malloc(sizeof(struct MyStruct));
userinfo->a = 1;
userinfo->b = 2;
NSTimer *myTimer = [NSTimer scheduledTimerWithInterval:0.05 target:self selector:@selector(myFireMethod:) userInfo:userinfo repeats:YES];
但是问题发生了,iOS 应用程序在运行 scheduledTimerWithInterval
方法时崩溃了。
'userinfo' 肯定有问题。可能的错误是什么?
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->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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
userInfo 必须是 Objective C 对象,因为它在赋值期间被保留。
如果你想传递 C 结构,你必须用 NSValue 包装它:
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: