这是奇怪的, 我在appDidfinsh方法中调用警报按钮,并根据该点击我调用viewController中定义的方法来停止计时器,但我不能停止但我可以访问我的方法可能重复:
NSTimer doesn't stop
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"check" message:@" this is 2nd time!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: @"Update",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 1) {
DatabaseTestViewController *vv=[ [DatabaseTestViewController alloc]init];
[viewController handleTime];
[vv handleTime];
}
}
//////////////现在在控制器类
中- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *getid = [NSUserDefaults standardUserDefaults];
getMode = [getid stringForKey:@"AppMode"];
timer = [NSTimer scheduledTimerWithTimeInterval: .8
target: self
selector: @selector(handleTimer)
userInfo: nil
repeats: YES];
}
- (void) handleTimer: (NSTimer *) timer
{
NSLog(@"getModis is %@",getMode);
// [self.tabelView reloadData];
//[super viewDidLoad];
} //
-(void) handleTime
{
[self.tabelView reloadData];// this is also not updating my data i actually need this
[timer invalidate];// not working , timer still running but i can access this method
[timer release];
timer =nil;
}