标签:style blog io color ar 使用 sp for strong
问题:
方案:
NSThread *thread = /* Get the reference to your thread here */; [thread cancel]; NSTimer *timer = /* Get the reference to your timer here */; [timer invalidate];
例如:
- (void) threadEntryPoint{ @autoreleasepool { NSLog(@"Thread Entry Point"); while ([[NSThread currentThread] isCancelled] == NO){
[NSThread sleepForTimeInterval:4]; NSLog(@"Thread Loop"); } NSLog(@"Thread Finished");
} } - (void) stopThread{ NSLog(@"Cancelling the Thread"); [self.myThread cancel]; NSLog(@"Releasing the thread"); self.myThread = nil; } - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.myThread = [[NSThread alloc] initWithTarget:self selector:@selector(threadEntryPoint) object:nil];
[self performSelector:@selector(stopThread) withObject:nil afterDelay:3.0f]; [self.myThread start];
return YES; }
打印为
...
Thread Entry Point
Cancelling the Thread
Releasing the thread
Thread Loop
Thread Finished
- (void) threadEntryPoint{ @autoreleasepool { NSLog(@"Thread Entry Point"); while ([[NSThread currentThread] isCancelled] == NO){ [NSThread sleepForTimeInterval:4]; if ([[NSThread currentThread] isCancelled] == NO){ NSLog(@"Thread Loop"); } } NSLog(@"Thread Finished"); } }
标签:style blog io color ar 使用 sp for strong
原文地址:http://www.cnblogs.com/safiri/p/4080952.html