ios - 以时间间隔执行选择器

标签 ios objective-c cocoa-touch

我有以下方法

-(void) showDie: (int) num;{
// do something
}

我想以 0.5 秒的时间间隔调用该方法。到目前为止,我有以下

SEL runShowDie;
[runShowDie performSelector:@selector(showDie:) withObject:rand];
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:runShowDie userInfo:nil repeats:NO];

我做错了什么?

最佳答案

您将重复:否在此行中设为是

    [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(showDie:) userInfo:[NSString stringWithFormat:@"%d",rand] repeats:YES];

关于ios - 以时间间隔执行选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399823/

相关文章:

ios - 如何像 Apple 的本地 map 应用程序那样进行本地搜索自动完成?

objective-c - 如何从 NSSet 实例中检索随机对象?

ios - 链接器错误编译 PDFKit

ios - 显式添加 @2x 到非 Retina 设备

ios - 如何在自定义键盘中输入自定义字体作为输入

iphone - 我想使用像 UIBezierPath 这样的任何关闭路径来裁剪图像。可以在 iPhone 应用程序中使用吗?

ios - 有时仅在 iOS 的后台更新位置

iphone - UITableview 编辑/完成按钮

iphone - 是否可以通过编程方式生成核心数据结构?

cocoa-touch - Cocoa 类通过单个键引用多个条目