你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> IOS 關於取消延遲執行函數的種種。performSelector與cancelPreviousPerformRequestsWithTarget

IOS 關於取消延遲執行函數的種種。performSelector與cancelPreviousPerformRequestsWithTarget

編輯:關於IOS

print?<PRE class=plain name="code">@interface NSObject (NSDelayedPerforming) 
 
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes; 
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay; 
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anArgument; 
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget; 
 
@end</PRE><BR> 
<BR> 
<PRE></PRE> 
<PRE class=cpp name="code"></PRE><PRE class=cpp name="code" sizcache="1" sizset="5">最近看到大家對cancelPreviousPerformRequestsWithTarget不能取消帶參數的<PRE class=cpp name="code">- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;</PRE>情況,寫了一點點代碼調試了一下,發現如果是帶參數,那取消時的參數也要一致,否則不能取消成功。 
<PRE></PRE> 
<PRE class=cpp name="code"></PRE><PRE class=cpp name="code">開始延遲執行:</PRE><PRE class=cpp name="code">[self performSelector:@selector(didRuninCurrModel:) withObject:[NSNumber numberWithBool:YES] afterDelay:3.0f]; 
     
[self performSelector:@selector(didRuninCurrModelNoArgument) withObject:nil afterDelay:3.0f];</PRE> 
<P><BR> 
</P> 
<P>假如在三秒內執行以下取消方法,則結果分別為:</P> 
<P></P> 
<PRE class=cpp name="code">    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:YES]];//可以取消成功。  
     
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:NO]];//不能取消成功。參數不匹配  
     
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:nil];//不能取消成功。參數不匹配  
     
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModelNoArgument) object:nil];//可以成功取消  
     
    [NSObject cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。  
    [[self class] cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。</PRE>  
<P></P> 
<P><BR> 
</P> 
<P><BR> 
</P> 
<BR> 
<BR> 
<P><BR> 
</P> 
<PRE></PRE> 
<PRE></PRE> 
 
</PRE> 

[plain]
@interface NSObject (NSDelayedPerforming)    - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes;  - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;  + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anArgument;  + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget;    @end  @interface NSObject (NSDelayedPerforming)

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes;
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anArgument;
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget;

@end

[cpp]
  [cpp]
最近看到大家對cancelPreviousPerformRequestsWithTarget不能取消帶參數的<PRE class=cpp name="code">- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;</PRE>情況,寫了一點點代碼調試了一下,發現如果是帶參數,那取消時的參數也要一致,否則不能取消成功。  <PRE></PRE>  <PRE class=cpp name="code"></PRE><PRE class=cpp name="code">開始延遲執行:</PRE><PRE class=cpp name="code">[self performSelector:@selector(didRuninCurrModel:) withObject:[NSNumber numberWithBool:YES] afterDelay:3.0f];        [self performSelector:@selector(didRuninCurrModelNoArgument) withObject:nil afterDelay:3.0f];</PRE>  <P><BR>  </P>  <P>假如在三秒內執行以下取消方法,則結果分別為:</P>  <P></P>  <PRE class=cpp name="code">    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:YES]];//可以取消成功。             [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:NO]];//不能取消成功。參數不匹配             [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:nil];//不能取消成功。參數不匹配             [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModelNoArgument) object:nil];//可以成功取消             [NSObject cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。       [[self class] cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。</PRE>   <P></P>  <P><BR>  </P>  <P><BR>  </P>  <BR>  <BR>  <P><BR>  </P>  <PRE></PRE>  <PRE></PRE>  最近看到大家對cancelPreviousPerformRequestsWithTarget不能取消帶參數的[cpp] view plaincopyprint?- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;  - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;情況,寫了一點點代碼調試了一下,發現如果是帶參數,那取消時的參數也要一致,否則不能取消成功。

[cpp] 
 [cpp]
開始延遲執行:  開始延遲執行:
[cpp]
[self performSelector:@selector(didRuninCurrModel:) withObject:[NSNumber numberWithBool:YES] afterDelay:3.0f];        [self performSelector:@selector(didRuninCurrModelNoArgument) withObject:nil afterDelay:3.0f];  [self performSelector:@selector(didRuninCurrModel:) withObject:[NSNumber numberWithBool:YES] afterDelay:3.0f];
   
[self performSelector:@selector(didRuninCurrModelNoArgument) withObject:nil afterDelay:3.0f];

假如在三秒內執行以下取消方法,則結果分別為:

[cpp]  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:YES]];//可以取消成功。     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:NO]];//不能取消成功。參數不匹配     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:nil];//不能取消成功。參數不匹配     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModelNoArgument) object:nil];//可以成功取消     [NSObject cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。   [[self class] cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。      [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:YES]];//可以取消成功。
   
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:NO]];//不能取消成功。參數不匹配
   
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:nil];//不能取消成功。參數不匹配
   
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModelNoArgument) object:nil];//可以成功取消
   
    [NSObject cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。
    [[self class] cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。

 

 

 

 

 

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved