iOS 取消延时执行 performSelector: withObject: afterDelay:

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.


    //[self setLayout];

    

    [self performSelector:@selector(Test:) withObject:@"参数" afterDelay:1.0];

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(Test:) object:@"参数"];

    

}


-(void)Test:(NSString *)str

{

   NSLog(@"延时执行正在执行,%@",str);

}

注意事项: 取消延时执行的参数一定要和延时执行的参数是一样的 



你可能感兴趣的:(iOS)