0

假设,在 Xcode 上的 xiphone 项目中,我有一个启动屏幕“a”,第一个视图“b”,第二个视图“c”,第二个视图上有一个“返回”按钮。现在我的任务是,当我的应用程序第一次启动时,将启动启动画面。然后将显示“b”。然后转到“c”。之后,当我再次启动应用程序时,将显示视图“c”。如果我想查看视图“b”,我必须在视图“c”上按“返回”按钮。否则视图“b”将永远不会显示。

这是我的问题。我该如何解决这个问题?

4

1 回答 1

0

您可以使用通知。因此,在视图控制器 C 中,您可以:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // add notification to be informed if the app becomes active while
    // this view controller is active, and if so, to invoke the
    // appDidBecomeActive method.

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(appDidBecomeActive)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];
}

- (void)appDidBecomeActive
{
    // do whatever you want in this method. for example, if you did
    // a modal segue (or presentViewController) to present this
    // view controller's view, then you'd dismiss like thus:

    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    // when this view disappears, we should remove the observer on
    // the UIApplicationDidBecomeActiveNotification

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIApplicationDidBecomeActiveNotification
                                                  object:nil];
}
于 2012-12-23T17:52:10.607 回答