1

I'm lacking a serious understanding of how modal transitions work, so please do not leave the simplest answer out of this.

I have two views with their own view controllers set up in storyboard. A button on the main-menu leads to other-view. I set up this transition purely via ctrl-click and selecting the modal transition. I also have a button leading from the other-view back to the main-menu, set up similarly.

To further my understanding of these transitions I decided that I want the main menu to play a sound when it loads up, but only the first time i hit run, and not again when i go hit the button the other-view to go back to menu-view.

in my menu-view I have a private property BOOL

@interface MainMenuViewController ()
@property BOOL menuSoundPlayed;
@end

and my viewDidLoad...

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (!self.menuSoundPlayed){
        //sound setup code omitted for clarity
        AudioServicesPlaySystemSound(mySound);
        self.menuSoundPlayed = YES;
    }
}

can someone help me understand why the menu sound plays every time main-menu view loads? I do acknowledge that the menuSoundPlayed is never really initialized, but I dont know where I would even do that.

side-note: I love that apple gives us all these conveniences like story-board, but I almost wish it was easier to see all the code behind these things, so i could actually understand what was going on when i 'segue' between views.

Anyways, thank you!

4

1 回答 1

1

我做了更多的研究并回答了我自己的问题。

在我之前遇到的情况(在我的问题中描述)我有代码

[self performSegueWithIdentifier:@"mainMenuSegue" sender:sender];

正在执行,正如评论者所描述的,它启动了我的主菜单的一个新实例。

我想要的是返回到已经创建的主菜单实例。

为此,需要以下代码(显然使用您自己的完成块):

[self dismissViewControllerAnimated:YES
                         completion:^{
                             NSLog("view dismissed");
                         }];
于 2013-01-12T03:34:18.970 回答