Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/45.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在后台3秒时间间隔后重复调用方法_Ios_Iphone_Objective C_Xcode_Nsthread - Fatal编程技术网

Ios 在后台3秒时间间隔后重复调用方法

Ios 在后台3秒时间间隔后重复调用方法,ios,iphone,objective-c,xcode,nsthread,Ios,Iphone,Objective C,Xcode,Nsthread,我浏览了很多网站,但仍然没有答案 我有一个方法假设void xyz(),在后每隔3秒从视图控制器自动调用 我不知道该使用什么,我是否必须使用NSThread或性能选择器。从ViewDidLoad方法调用此方法。当您的视图显示在iPhone设备或模拟器中时,ViewDidLoad将显示 [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(runMethod) userInfo:nil repeats

我浏览了很多网站,但仍然没有答案

我有一个方法假设
void xyz()
后每隔3秒从视图控制器自动调用


我不知道该使用什么,我是否必须使用NSThread性能选择器。

从ViewDidLoad方法调用此方法。当您的视图显示在iPhone设备或模拟器中时,ViewDidLoad将显示

[NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(runMethod) userInfo:nil repeats:YES];


    -(void)runMethod

    {

    }

像这样的

-(void)xyz{
        [self performSelectorInBackground:@selector(xyz) withObject:nil];
    }

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

使用
NSTimer

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(xyz) userInfo:nil repeats:YES];

您应该使用@mokujin提到的NSTimer。 请访问