2013-12-16 56 views
0

在過去的幾天裏,我試圖調查我最近發現的非常奇怪的情況。 事情是,推控制器看起來在popViewControllerAnimated:呼叫後保持活着。 我已經創建了簡單的測試項目(ARC啓用)與兩個控制器嵌入根控制器和行爲已被複制。 enter image description here 這是第一次的viewController代碼fireing第二控制器:在popViewControllerAnimated之後,UINavigationController不釋放/銷燬控制器?

-(IBAction)push:(id)sender { 
    [self performSegueWithIdentifier:@"vseg" sender:nil]; 
} 

沒有什麼不尋常,從我的角度探討。還有在第二控制器的方法是由定時器稱爲每一秒:

-(void) ticker { 
    NSLog(@"from ViewController2 %d", tickerCount++); 
    _counterLabel.text = [NSString stringWithFormat:@"tick: %d", tickerCount]; 
    [self performSelector:@selector(ticker) withObject:nil afterDelay:1]; 
} 

仍然沒有什麼不尋常 - 應用程序正常工作,用遞增的tickerCount價值和信息的UILabel更新出現在控制檯。 接下來我們點擊返回按鈕,第一個控制器彈出,控制檯繼續接收來自第二個控制器的消息。 enter image description here

我仍然不知道它究竟意味着什麼? Wheer整個控制器保持未釋放狀態,或者只是由一些不感興趣的clousure變量持有的ticker方法。 下面是測試項目http://hxml.ru/EliEX

+0

控制器未釋放,因爲其定時器處於活動狀態。嘗試另一種'清除'測試:以控制器的'dealloc'方法記錄信息。 ARC概念中沒有dealloc限制 – brigadir

+0

? – heximal

+0

爲您的股票代碼方法,爲什麼不使用'NSTimer'來實現? – chancyWu

回答

1

取消選擇只使用

[NSObject cancelPreviousPerformRequestsWithTarget:self]; 

[NSObject cancelPreviousPerformRequestsWithTarget:selector:object:] 

的目標是在其performSelector:afterDelay:被稱爲

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [NSObject cancelPreviousPerformRequestsWithTarget:self]; 
} 

指原始對象Run Loops a nd NSObject docs

+0

CLLocationManager如何向控制器發送位置和標題事件?即使在控制器被放棄之後,它仍會繼續發送它們。蘋果的手冊沒有說明什麼,你必須明確地停止它? https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/GettingHeadings/GettingHeadings.html – heximal

+0

請將其作爲單獨的問題與您的代碼一起發佈。 – suhit

相關問題