2012-01-05 65 views
0

有沒有辦法在NStimer打開0後打開一個新屏幕?NStimer新屏幕後

e.x:

-(void) randomMainVoid { 

    if (mainInt <= 0) 
    { 
     [randomMain invalidate]; 

     //after counting a code to open a new file (new .h/.m/.xib file) 

    } else { 

    //something 

    } 
} 

回答

1

如果您在使用標準視圖控制器/筆尖模型,這是很容易裝入一個新的屏幕。但是,如何呈現它將取決於您的應用程序。但是,作爲一個例子,如果你想提出一個新的模式後屏幕計時器完成,你有一個名爲AfterTimerViewController與相關的筆尖文件視圖控制器類,你會提出它是這樣:

-(void) randomMainVoid 
{ 
    if (mainInt <= 0) { 
    [randomMain invalidate]; 

    // This assumes this method is defined in the current view 
    // controller. If not, replace self with the appropriate reference 
    AfterTimerViewController* controller = [[AfterTimerViewController alloc] initWithNibName:@"AfterTimerViewController" bundle:nil]; 
    // Uncomment and use for pushing onto a navigation controller's stack 
    [[self navigationController] pushViewController:controller animated:YES]; 

    // Uncomment and use if you want the new view controller to replace the root of your 
    // current navigation controller stack 
    //[[self navigationController] setViewControllers:[NSArray arrayWithObject:controller] animated:YES]; 

    // Uncomment and use for presenting the new controller as a modal view controller 
    //[self presentModalViewController:controller animated:YES]; 

    [controller release]; // change this if you're using ARC or taking ownership of this controller accordingly 
    } else { 
    //something 
    } 
} 

對於有關這些方法的更多信息,請參見UIViewController documentationView Controller Programming Guide for iOS

編輯:我添加示例代碼爲一些不同的公共轉換。最好的辦法是閱讀有關視圖控制器及其交互的指南,以便您可以使用最適合應用程序設計的模式。通常,上面的示例代碼展示瞭如何對事件做出反應,以編程方式創建視圖控制器並呈現它。

+0

謝謝,但該導航欄沒有顯示? – Blazer 2012-01-05 22:30:33

+1

@Nathan請閱讀我鏈接的評論和指南。如果您使用的是導航控制器,則會將新視圖放到導航控制器的堆棧上,而不是以模態方式顯示。儘管如此,您沒有提供任何有關如何在您的問題中設置UI的信息。我將編輯我的答案以推動控制器而不是以模態方式呈現它。 – 2012-01-05 22:33:57