nstimer userinfo.كيف يمر الكائن إلى محدد؟
سؤال
لدي هذا الرمز: giveacodicetagpre.
الهدف هو البدء في تدوير وجهة نظر بينما يحمل المستخدم زر.عندما يطلق المستخدم فسوف يتوقف الموقت.
لكنني أعطي هذا:
- [__ nscftimer intvalue]: محدد غير معروف المرسل إلى مثيل 0x4AE360
ولكن إذا كنت أتبافيا في userinfo فئة NSNumber، لماذا أتلقى الموقت؟
شكرا.
المحلول
Your timer action method should look like this
-(void)rotateSelectedItem:(NSTimer*)sender
You can get at the userInfo by doing
NSNumber *userInfo = sender.userInfo;
نصائح أخرى
You misunderstood the signature of the selector that you register with the timer. The sender is NSTimer*
, not the userInfo object that you pass into its constructor:
-(void)rotateSelectedItem:(NSTimer*)sender
{
float currAngle = [selectedItem currentRotation];
if ([sender.userInfo intValue] == RDUtilitiesBarRotationLeft)
{
[selectedItem rotateImage:currAngle - 1];
}
else
{
[selectedItem rotateImage:currAngle + 1];
}
}
From the documentation:
The message to send to target when the timer fires. The selector must have the following signature:
- (void)timerFireMethod:(NSTimer*)theTimer
لا تنتمي إلى StackOverflow