我在countDown的末尾使用了NSTimer &想要更改[email protected]"Time Up"
的值。这是完美的工作,直到我切换到其他ViewController之后切换之间切换viewController(&回来这个viewController)时,countDown完成我越来越完美的价值&他们是没有零,但View.UILabel.text值没有改变,我已经检查异常,没有发生异常。view.UILabel.text在viewControllers之间切换后不改变
我的代码:
-(void) timeInterval
{
appdelegate._UserProfile.totalTime = 30;
UIApplication *app = [UIApplication sharedApplication];
//will allow NSTimer to continue running in background..
UIBackgroundTaskIdentifier bgTask = 0;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
appdelegate._UserProfile.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
}
-(void) countDown
{
appdelegate._UserProfile.totalTime -= 1;
if(appdelegate._UserProfile.totalTime == 0)
{
[profileView.userPhoneNo setText:@""];
profileView.timeUp.text= @"* Time Up";
}
}
请任何帮助将是非常赞赏。 (我看到很多问题,但我的问题没有解决)
*注意:切换后,如果我更改ViewWillAppear()中的标签的值它工作完美,但我需要改变countDown完成时的文本。我正在使用UINavigationController & MFSideMenuManager
在ViewControllers之间切换。
我的导航代码:
-(void) initMyProfile
{
UINavigationController *detailNavigationController = [MFSideMenuManager sharedManager].navigationController;
detailNavigationController.menuState = MFSideMenuStateHidden;
MyProfileViewController_iPhone* detailViewController = [[MyProfileViewController_iPhone alloc] initWithNibName:nil bundle:nil];
detailViewController.title = @"My Profile";
detailNavigationController.viewControllers = [NSArray arrayWithObject:detailViewController];
}
我没有使用Segue,而是以编程方式做每件事 – 2014-12-03 11:47:12
你可以在你的“Time Up”代码块中放置一个断点,看它是否被调用?如果它确实存在,但你没有看到显示的结果,我想可能是你有多个实例。在你的View Controller的初始化器中尝试一个断点,看它是否被多次执行。 – Clafou 2014-12-03 11:50:49
是的,我已经通过放置断点来检查它是否正在调用“Time Up”块 – 2014-12-03 11:52:24