[NSTimer]NSTimer你真的會用了嗎
阿新 • • 發佈:2019-01-04
- (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // test Timer retain target [self testNonRepeatTimer]; // [self testRepeatTimer]; } - (void)testNonRepeatTimer { NSLog(@"Test retatin target for non-repeat timer!"); SvTestObject *testObject = [[SvTestObject alloc] init]; [NSTimer scheduledTimerWithTimeInterval:5 target:testObject selector:@selector(timerAction:) userInfo:nil repeats:NO]; [testObject release]; NSLog(@"Invoke release to testObject!"); } - (void)testRepeatTimer { NSLog(@"Test retain target for repeat Timer"); SvTestObject *testObject2 = [[SvTestObject alloc] init]; [NSTimer scheduledTimerWithTimeInterval:5 target:testObject2 selector:@selector(timerAction:) userInfo:nil repeats:YES]; [testObject2 release]; NSLog(@"Invoke release to testObject2!"); }