<i id='LMvX1'><tr id='LMvX1'><dt id='LMvX1'><q id='LMvX1'><span id='LMvX1'><b id='LMvX1'><form id='LMvX1'><ins id='LMvX1'></ins><ul id='LMvX1'></ul><sub id='LMvX1'></sub></form><legend id='LMvX1'></legend><bdo id='LMvX1'><pre id='LMvX1'><center id='LMvX1'></center></pre></bdo></b><th id='LMvX1'></th></span></q></dt></tr></i><div id='LMvX1'><tfoot id='LMvX1'></tfoot><dl id='LMvX1'><fieldset id='LMvX1'></fieldset></dl></div>
  • <small id='LMvX1'></small><noframes id='LMvX1'>

    • <bdo id='LMvX1'></bdo><ul id='LMvX1'></ul>

      <tfoot id='LMvX1'></tfoot>

      <legend id='LMvX1'><style id='LMvX1'><dir id='LMvX1'><q id='LMvX1'></q></dir></style></legend>

        Objective C - XCode无法识别if语句之外的变量

        时间:2024-08-12
          <tbody id='UktrP'></tbody>
          1. <small id='UktrP'></small><noframes id='UktrP'>

            <i id='UktrP'><tr id='UktrP'><dt id='UktrP'><q id='UktrP'><span id='UktrP'><b id='UktrP'><form id='UktrP'><ins id='UktrP'></ins><ul id='UktrP'></ul><sub id='UktrP'></sub></form><legend id='UktrP'></legend><bdo id='UktrP'><pre id='UktrP'><center id='UktrP'></center></pre></bdo></b><th id='UktrP'></th></span></q></dt></tr></i><div id='UktrP'><tfoot id='UktrP'></tfoot><dl id='UktrP'><fieldset id='UktrP'></fieldset></dl></div>
          2. <tfoot id='UktrP'></tfoot>

                  <bdo id='UktrP'></bdo><ul id='UktrP'></ul>
                • <legend id='UktrP'><style id='UktrP'><dir id='UktrP'><q id='UktrP'></q></dir></style></legend>

                  本文介绍了Objective C - XCode无法识别if语句之外的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  尝试使用 if 语句设置 sprite 文件名,然后根据该字符串加载正确的文件.看起来我的变量范围有问题,但我不知道它是什么.

                  Trying to set a sprite filename with an if statement, then load the proper file based on that string. It looks like there's a problem with my variable scope, but I don't know what it is.

                  这是我的代码:

                  if ([[GameManager sharedGameManager] newHighScore] == TRUE) {
                      NSString *highScoreLabelText = @"label-new-high-score.png"
                  } else {
                      NSString *highScoreLabelText = @"label-high-score.png"
                  }
                  
                  CCSprite *highScoreLabel = [CCSprite spriteWithSpriteFrameName:highScoreLabelText];
                  [highScoreLabel setAnchorPoint:ccp(0,0)];
                  [highScoreLabel setPosition:ccp(20, winSize.height * 0.575f)];
                  [self addChild:highScoreLabel];
                  

                  XCode 正在标记一个错误,指出 highScoreLabelText 是一个未声明的标识符,因此不会编译应用程序.我是否需要与 NSString 一起声明其他内容才能让其余代码与变量一起使用?

                  XCode is flagging an error, saying that highScoreLabelText is an undeclared identifier, and thus won't compile the app. Do I need to declare something else along with the NSString to get the rest of the code to work with the variable?

                  推荐答案

                  这是因为您在 if 的两个分支中声明了两个单独的内部范围变量.这两个变量在其范围之外都不可见,因此您会遇到错误.

                  This is because you declared two separate inner-scope variables in both branches of if. Neither of these two variables is visible outside its scope, so you are getting an error.

                  你应该把声明移出if,像这样:

                  You should move the declaration out of if, like this:

                  NSString *highScoreLabelText;
                  if ([[GameManager sharedGameManager] newHighScore] == TRUE) {
                      highScoreLabelText = @"label-new-high-score.png"
                  } else {
                      highScoreLabelText = @"label-high-score.png"
                  }
                  

                  现在 highScoreLabelText 在您的 if 语句之外可见.

                  Now highScoreLabelText is visible outside of your if statement.

                  这篇关于Objective C - XCode无法识别if语句之外的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 cocos2d 引擎中实现二维码阅读器 下一篇:着色器程序在 Cocos2d 2.2 Obj.C iOS 12 中不起作用

                  相关文章

                    <bdo id='4wxz9'></bdo><ul id='4wxz9'></ul>
                  <tfoot id='4wxz9'></tfoot>

                  <i id='4wxz9'><tr id='4wxz9'><dt id='4wxz9'><q id='4wxz9'><span id='4wxz9'><b id='4wxz9'><form id='4wxz9'><ins id='4wxz9'></ins><ul id='4wxz9'></ul><sub id='4wxz9'></sub></form><legend id='4wxz9'></legend><bdo id='4wxz9'><pre id='4wxz9'><center id='4wxz9'></center></pre></bdo></b><th id='4wxz9'></th></span></q></dt></tr></i><div id='4wxz9'><tfoot id='4wxz9'></tfoot><dl id='4wxz9'><fieldset id='4wxz9'></fieldset></dl></div>

                  <small id='4wxz9'></small><noframes id='4wxz9'>

                • <legend id='4wxz9'><style id='4wxz9'><dir id='4wxz9'><q id='4wxz9'></q></dir></style></legend>