Iphone 在我的UIView中每隔5分钟调用一次方法

Iphone 在我的UIView中每隔5分钟调用一次方法,iphone,objective-c,ios,Iphone,Objective C,Ios,我想在我的UIView代码中调用一个特定的方法,比如说每5分钟调用一次-我如何做到这一点?您可以使用NSTimer来实现这一点 具体来说 timerWithTimeInterval:target:selector:userInfo:repeats: 类方法 您可以使用NSTimer: 将以下内容放入viewDidLoad(其中300是秒数): 然后创建更新方法: - (void)updateMethod:(NSTimer *)theTimer { // Your code goes h

我想在我的UIView代码中调用一个特定的方法,比如说每5分钟调用一次-我如何做到这一点?

您可以使用NSTimer来实现这一点

具体来说
timerWithTimeInterval:target:selector:userInfo:repeats:

类方法

您可以使用NSTimer:

将以下内容放入viewDidLoad(其中300是秒数):

然后创建更新方法:

- (void)updateMethod:(NSTimer *)theTimer {
    // Your code goes here
}

有一个简单的方法可以做到这一点,在您的更新方法

-(void)update{
     //Your update methods here
     [self performSelector:@selector(update) withObject:nil afterDelay:300.0];
}

NSTimer
,以及
performSelector:withObject:afterDelay:
来命名一对
-(void)update{
     //Your update methods here
     [self performSelector:@selector(update) withObject:nil afterDelay:300.0];
}