经过NStimer的新画面

时间:2012-01-05 20:54:19

标签: objective-c

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 个答案:

答案 0 :(得分:1)

如果您使用的是标准视图控制器/笔尖模型,则加载新屏幕非常容易。但是,如何呈现它将取决于您的应用程序。但是,作为一个例子,如果你想在计时器结束后提出一个新的模态屏幕,并且你有一个名为AfterTimerViewController的视图控制器类,并带有一个相关的nib文件,你可以这样呈现:

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

编辑:我为许多不同的常见转换添加了示例代码。最好的方法是阅读有关View Controllers及其交互的指南,以便您可以使用最适合您的应用程序设计的模式。通常,上面的示例代码显示了如何对事件做出反应,以编程方式创建视图控制器并将其呈现。