简体   繁体   中英

iPhone app reusing a view displays black screen

So I'm trying to finish this iPhone app I started years ago. Anyway, I have an options menu, from which you can create a custom level (which goes to another view). Then when I return to the main menu, then the options menu, it just displays a black screen.

// shows options menu, works the first time
-(void) options : (id) sender{
    [self.menuViewController.view removeFromSuperview];
    [self.bg.view removeFromSuperview];
    [self transition:self.view :navController.view];
}

// goes to custom built level
- (void) createCustom : (int) colorCount : (int) width : (int) height : (int) shuffles : (int) partners : (ToggleMode) toggleMode : (BOOL) colorblind{
    self.gameViewController.isCustom = true;
    self.gameViewController.width = width;
    self.gameViewController.height = height;
    self.gameViewController.shuffles = shuffles;
    self.gameViewController.partners = partners;
    self.gameViewController.toggleMode = toggleMode;
    self.gameViewController.colorCount = colorCount;

    srandom(arc4random());

    [self.navController setNavigationBarHidden:true];
    [self.gameViewController goToLevel];

    [self transition:self.optionsMenu.customLevel.view : gameViewController.view];
}

- (void) transition : (UIView *) fromView : (UIView *) toView{
    [UIView transitionFromView:fromView toView:toView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight completion:NULL];
}

When I print out the objects involved, they all seem to still be there, so I have NO idea why it's just showing black. Please help me finish this app!

Why not display your options menu using a ModalViewController ? It will display overtop your existing ViewController and will not dismiss/dealloc it. This will also remove the need to manually remove the views and view controller before transition, which is probably what is causing your black screen issue. You can add a button on this modal to dismiss it after the user has finished looking through the options.

Also as a general point on objective c, to make your life easier you should follow the correct format for naming methods. This involves putting the name of the parameter before each parameter in order to make calling the method much less confusing. As an example:

- (void)createCustom:(int)colorCount
                    :(int)width
                    :(int)height
                    :(int)shuffles
                    :(int)partners
                    :(ToggleMode)toggleMode
                    :(BOOL)colorblind {
}

Would turn into something like:

- (void)createCustomColorCount:(int)colorCount
                              withWidth:(int)width
                              withHeight:(int)height
                              withNumberOfShuffles:(int)shuffles
                              WithNumberOfPartners:(int)partners
                              withToggleMode:(ToggleMode)toggleMode
                              setColorBlind:(BOOL)colorblind {
}

To demonstrate why this is helpful, here is an example of how you would call your method:

[self createCustom:0
                  :100
                  :100
                  :5
                  :5
                  :nil
                  :NO];

versus:

[self createCustomColorCount:0
                   withWidth:100
                  withHeight:100
        withNumberOfShuffles:5
        WithNumberOfPartners:5
              withToggleMode:nil
               setColorBlind:NO];

As you can see with the second method it is much more clear what each parameter value corresponds to without having to go back to the implementation of the method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM