iphone - 我想以不同的时间间隔多次调用一个方法

标签 iphone objective-c ios

我有一个方法 -(void)showLyrics{} 我想从另一个方法调用它,但在一段时间后,每次连续调用之间的时间调用是不同的。 我就是这样做的

[self performSelector:@selector(showLyrics) withObject:nil afterDelay:2];

[self performSelector:@selector(showLyrics) withObject:nil afterDelay:5];

[self performSelector:@selector(showLyrics) withObject:nil afterDelay:10];

[self performSelector:@selector(showLyrics) withObject:nil afterDelay:12];

有人知道更好的方法吗?

最佳答案

调用一次

-(void)viewDidLoad {
    [self performSelector:@selector(showLyrics) withObject:nil afterDelay:2];
}

做你的事 然后安排下一次

-(void)showLyrics {
    int d=2;
    //do your thing
    d+=3;//or whatever
    [self performSelector:@selector(showLyrics) withObject:nil afterDelay:d];

}

关于iphone - 我想以不同的时间间隔多次调用一个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13172584/

相关文章:

iphone - 使用自定义动画推送 View Controller

iphone - 获取经度和纬度值

iOS - 删除 UITabBarViewController 阴影

ios - 场景无法访问...没有标识符

ios - 在另一个 UIImageView 完成后使 UIImageView 动画化

iphone - 如何绘制条形图和饼图 iPhone sdk?

iphone - UITableViewscrollToRowAtIndexPath

iphone - 如何从推送 segue 中解雇带有 Storyboard的 viewController?

ios - 如何将 "http://"添加到字符串(如果缺少)

ios - 如何在 Web 的轮播 View 中显示图像?