Created
          December 11, 2015 07:57 
        
      - 
      
 - 
        
Save 0xlitf/8a6adc94671fdd4e45ea to your computer and use it in GitHub Desktop.  
    cancelPreviousPerformRequestsWithTarget.m
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(overtimeRemind) object:nil]; | |
| 先看这段代码: | |
| - (void)viewDidAppear:(BOOL)animated { | |
| [super viewDidAppear:animated]; | |
| [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showLeft) object:nil]; | |
| [self performSelector:@selector(showLeft)]; | |
| } | |
| - (void)viewDidAppear:(BOOL)animated { | |
| [super viewDidAppear:animated]; | |
| [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showLeft) object:nil]; | |
| [self performSelector:@selector(showLeft)]; | |
| } | |
| 为什么[self performSelector:@selector(showLeft)];前面还需要调用cancelPreviousPerformRequestsWithTarget:self方法呢? | |
| 那是因为有时候我们通过[self performSelector:@selector(showLeft)];来实现showLeft方法,可能会出现延迟执行或内存泄漏的问题,而前面加上这句话: | |
| [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showLeft) object:nil]; | |
| 可以先将这在执行的方法取消,在继续执行,有效避免了上述两个问题。 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment