延迟调用和取消延迟调用

performSelector这二个方法是延迟调用的方法。
cancel是取消延迟调用的方法。
具体用法详解:

NSString * parm = @"againSureOrderView";
[self performSelector:@selector(textwithparm:) withObject:parm afterDelay:5.0];

NSString * parm = @"againSureOrderView";
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(textwithparm:) object:parm];

  • (void)textwithparm:(NSString *)parm{
    [self.View removeFromSuperview];
    }
  1. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), methodBlock);

    dispatch_block_cancel(methodBlock);

dispatch_block_t methodBlock = ^{
NSLog(@"do something");
};

你可能感兴趣的:(延迟调用和取消延迟调用)