簡體   English   中英

在viewControllers之間切換后,View.UILabel.text保持不變

[英]View.UILabel.text not changing after switch between viewControllers

我已經使用NSTimer&在countDown末尾要更改View.UILabel.text=@"Time Up" 這是完美的,直到我切換到其他ViewController,在countDown完成后在viewController(&返回此viewController)之間切換之后,我得到了完美的值,並且它們都不為零,但是View.UILabel.text的值沒有改變,我已經檢查了異常,沒有異常引發。

我的代碼:

-(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()中的label的值,則可以正常工作,但是當countDown完成時,我需要更改文本。 我正在使用UINavigationController & MFSideMenuManager在ViewController之間切換。

我的導航代碼:

-(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];

}

一種可能的解釋是您不是回到原始的視圖控制器,而是回到一個新的新實例。 使用標准序列而不是展開序列時,很容易發生這種情況。

在發生類似問題的地方,請參見另一個問題: 在方法內部更改標簽文本

如果要通過單擊后退導航按鈕並在viewDidLoad上調用此方法來返回視圖,那就是問題所在。

僅在創建視圖控制器后才調用viewDidLoad,要在每次打開視圖控制器時調用這些方法,請在viewWillAppear上調用這些方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM