现在的位置: 首页 > 编程语言 > 正文

objective 取消执行的延迟函数 — 线程

2018年09月08日 编程语言 ⁄ 共 1160字 ⁄ 字号 评论关闭

//延迟执行

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

 

//取消延迟执行

[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(hidenSelf) object:nil];

访问官网:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html

Sending Messages

下面给出一个例子:

- (IBAction)Start:(id)sender {
    [self performSelector:@selector(doSomething:)];
    //[self doSomething:nil];
    //[self per
    [self performSelectorInBackground:@selector(doSomething:) withObject:nil];
   
}
-(void)doSomething:(id)inputData
{
    if([NSThread isMainThread])
    {
        NSLog(@"in main thread");
       
    }
    else {
        NSLog(@"not in main thread");
    }
    NSLog(@"kkkkk");
}

抱歉!评论已关闭.