2012-06-19 47 views
0

我正在使用兩個視圖控制器進行應用程序。當我在我的第一個觀點工作,我有posibility使用「設置」按鈕,並conected到該按鈕的方法去另一個觀點是這樣的:presentModalViewController不起作用?

-(IBAction)Settings:(id)sender{ 

[self presentModalViewController:settingsHandle animated:YES]; 

settingsHandle是第二視圖類的一個對象,它是alloceted當第一個視圖被加載時。

我的問題開始,而我在第二個視圖,我打電話的方法,其中包括NSTimer對象。這個方法在hmmm工作時可以說30秒,但也可以是5分鐘,這種方法的結果是在其他視圖中調用第三個視圖。

當我在第二個視圖中等待此功能的結果時,一切正常。結果是我處於第三個視圖。

在方法工作期間,我將從第二個視圖開始(使用[self dismissModalViewControllerAnimated:YES];)我可以看到該方法已完成(使用NSLOG),但[self presentModalViewController:thirdview animated:YES];不起作用,只是沒有任何反應。

這樣總結:

等待結果的過程中secodnview(更迭第三種觀點上傳) 中的firstView等待結果(失敗沒有任何反應)

而且我的目標是使它發生在第一個視圖!

+0

你使用ARC(自動參考計數)?如果是這樣,當你的定時器的最後一個引用,可能在你的2.ViewController中消失,定時器將被釋放,因此它不會調用任何東西。 – Phlibbo

+0

不,我不使用ARC;/ – user1246957

+0

你的[self presentModalViewController:thirdview animated:YES]的「自我」;自然會成爲你的第一個視圖控制器,對嗎? – Phlibbo

回答

0

您不能提出被解僱的ViewController中的ModalViewController。所以,你需要跟蹤可見的ViewController並從那裏撥打presentModalViewController。在你的情況下,最簡單的解決辦法是讓你的第一個ViewController如果您在2 ViewController創建的NSTimer這是這樣的

- (void)presentViewController:(NSTimer *)timer 
{ 
    if(self.modalViewController == nil) 
     [self presentModalViewController:settingsHandle animated:YES]; 
    else 
     [self.modalViewController presentViewController]; 
} 

NSTimer調用一個方法,當然你需要一個參考第一個ViewController。你可以通過這樣的參考

-(IBAction)Settings:(id)sender{ 
    settingsHandle.myParentViewController = self; //You need to create this var in settingsHandle 
    [self presentModalViewController:settingsHandle animated:YES]; 
    //... 
} 
相關問題