Ios 按时间间隔执行选择器

Ios 按时间间隔执行选择器,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我有以下方法 -(void) showDie: (int) num;{ // do something } 我想以.5秒的时间间隔调用该方法。到目前为止,我有以下几点 SEL runShowDie; [runShowDie performSelector:@selector(showDie:) withObject:rand]; [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:runShowDie userInfo

我有以下方法

-(void) showDie: (int) num;{
// do something
}
我想以.5秒的时间间隔调用该方法。到目前为止,我有以下几点

SEL runShowDie;
[runShowDie performSelector:@selector(showDie:) withObject:rand];
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:runShowDie userInfo:nil repeats:NO];
我做错了什么?

试试看

[self performSelector:@selector(showDie:) withObject: rand afterDelay:0.5f];

然后删除您在这行中放置的repeats:No,使其成为YES

    [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(showDie:) userInfo:[NSString stringWithFormat:@"%d",rand] repeats:YES];
这会产生一个错误“ARC不允许将'int'隐式转换为'id'。我忘了提到rand是传递给showDie方法的int参数