简体   繁体   English

重用视图的iPhone应用显示黑屏

[英]iPhone app reusing a view displays black screen

So I'm trying to finish this iPhone app I started years ago. 因此,我正在尝试完成几年前启动的iPhone应用程序。 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 ? 为什么不使用ModalViewController显示选项菜单? It will display overtop your existing ViewController and will not dismiss/dealloc it. 它将显示在现有ViewController的上方,并且不会关闭/取消分配它。 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. 同样,关于目标c的一般要点是,为了使您的生活更轻松,您应遵循正确的命名方法格式。 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. 从第二种方法可以看出,每个参数值对应什么都更加清楚,而不必返回该方法的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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