• <tfoot id='4KRXD'></tfoot>

        <legend id='4KRXD'><style id='4KRXD'><dir id='4KRXD'><q id='4KRXD'></q></dir></style></legend>
      1. <small id='4KRXD'></small><noframes id='4KRXD'>

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

        可能的循环引用问题

        Possible circular reference problem(可能的循环引用问题)
          <tfoot id='c3mwD'></tfoot>
        • <legend id='c3mwD'><style id='c3mwD'><dir id='c3mwD'><q id='c3mwD'></q></dir></style></legend>

              <tbody id='c3mwD'></tbody>

              <bdo id='c3mwD'></bdo><ul id='c3mwD'></ul>
            • <small id='c3mwD'></small><noframes id='c3mwD'>

                1. <i id='c3mwD'><tr id='c3mwD'><dt id='c3mwD'><q id='c3mwD'><span id='c3mwD'><b id='c3mwD'><form id='c3mwD'><ins id='c3mwD'></ins><ul id='c3mwD'></ul><sub id='c3mwD'></sub></form><legend id='c3mwD'></legend><bdo id='c3mwD'><pre id='c3mwD'><center id='c3mwD'></center></pre></bdo></b><th id='c3mwD'></th></span></q></dt></tr></i><div id='c3mwD'><tfoot id='c3mwD'></tfoot><dl id='c3mwD'><fieldset id='c3mwD'></fieldset></dl></div>
                  本文介绍了可能的循环引用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我不是白痴,但头文件有时让我觉得自己像个白痴.我有一个可能过于复杂的设置,它有一个我无法解决的错误.这是我能做到的尽可能简单的细节......

                  I am not an idiot, but header files make me feel like one sometimes. I have what is probably an overly-complicated set-up that has an error that I cannot resolve. Here it is in about as simple as detail as I can make it....

                  • 我有一个包含模型类的控制器类.
                  • 我有一个 Scene 类来捕捉动作并与控制器通信.
                  • 我有一个 Layer 类,它与 Model 类对话以输出 Model 的状态.
                  • Scene 类包含仅用于输出的 Layer 类.
                  • 场景必须包含 Cocos2D 框架确定的层.
                  • 特定场景类派生自 RootScene 类,该类包含对 Controller 类的引用.
                  • 特定的 Layer 类派生自 RootLayer 类,该类包含对 Model 类的引用.
                  • 控制器负责创建场景,场景负责创建层.

                  当创建一个层并将控制器的模型传递给层的模型(在 AScene.m 中)时,问题就出现了.我收到在非结构或联合的情况下请求成员‘模型’".铸造不起作用,我不知道如何让这些类相互交谈.我认为部分问题可能是 Controller 类包含 Model 类.

                  The problem comes when making a Layer and passing the Controller's Model to the Layer's Model (in AScene.m). I get the "Request for member 'Model' in something not a stucture or union". Casting doesn't work, and I'm at a loss for how to allow these classes to talk with each other. I think part of the problem might be that Controller class contains the Model class.

                  Controller.h

                  #import <Foundation/Foundation.h>
                  
                  @class Model;
                  @class AScene;
                  
                  @interface Controller : NSObject {
                      Model *Model;
                  }
                  @property (nonatomic, retain) Model *Model;
                  -(void)runScene;
                  

                  Controller.m

                  #import "Controller.h"
                  
                  #import "Model.h"
                  #import "AScene.h"
                  
                  @implementation Controller
                  
                  @synthesize Model;
                  
                  - (void)runScene {
                      AScene *newScene = [[AScene alloc] init];
                      newScene.controller = self;
                  }
                  

                  RootScene.h

                  #import "cocos2d.h"
                  
                  @class Controller;
                  
                  @interface RootScene : Scene {
                      Controller *controller;
                  }
                  @property (nonatomic, retain) Controller *controller;
                  
                  @end
                  

                  RootScene.m

                  #import "RootScene.h"
                  #import "Controller.h"
                  
                  @implementation RootScene
                  
                  @synthesize controller;
                  
                  - (id) init {
                      self = [super init];
                      if (self != nil) {
                          //
                      }
                      return self;
                  }
                  
                  - (void) dealloc {
                      [controller release];
                      [super dealloc];
                  }
                  
                  @end
                  

                  AScene.h

                  #import "RootScene.h"
                  
                  @class ALayer;
                  @class Model;
                  
                  @interface AScene : RootScene {
                  }
                  
                  @end
                  

                  AScene.m

                  #import "AScene.h"
                  #import "ALayer.h"
                  #import "Model.h"
                  
                  @implementation AScene
                  
                  - (id) init {
                      self = [super init];
                      if (self != nil) {
                          ALayer *newLayer = [ALayer node];
                          newLayer.model = controller.Model; // <-- Request for member 'Model' in something not a stucture or union
                          [self addChild:statusScreenLayer];
                      }
                      return self;
                  }
                  
                  - (void) dealloc {
                      [super dealloc];
                  }
                  
                  @end
                  

                  RootLayer.h

                  #import "cocos2d.h"
                  
                  @class Model;
                  
                  @interface RootLayer : Layer {
                      Model *model;
                  }
                  @property (nonatomic, retain) Model *model;
                  
                  @end
                  

                  RootLayer.m

                  #import "RootLayer.h"
                  
                  #import "Model.h"
                  
                  @implementation RootLayer
                  
                  @synthesize model;
                  
                  - (id) init {
                      self = [super init];
                      if (self != nil) {
                          //
                      }
                      return self;
                  }
                  
                  - (void) dealloc {
                      [model release];
                      [super dealloc];
                  }
                  
                  @end
                  

                  ALayer.h

                  #import "RootLayer.h"
                  
                  @interface ALayer : RootLayer {
                  }
                  -(void) draw;
                  
                  @end
                  

                  ALayer.m

                  #import "ALayer.h"
                  
                  @implementation ALayer
                  
                  -(void) draw {
                      // draw based on state of the model
                  }
                  
                  @end
                  

                  推荐答案

                  你的AScene实现没有#importController的header.

                  Your implementation of AScene does not #import the header of Controller.

                  显式解决方案.

                  在 AScene.m 中添加:

                  In AScene.m add:

                  #import "Controller.h"
                  

                  这篇关于可能的循环引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Resume game cocos2d(恢复游戏 cocos2d)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
                      <tbody id='ZUaap'></tbody>
                  • <tfoot id='ZUaap'></tfoot>
                    <i id='ZUaap'><tr id='ZUaap'><dt id='ZUaap'><q id='ZUaap'><span id='ZUaap'><b id='ZUaap'><form id='ZUaap'><ins id='ZUaap'></ins><ul id='ZUaap'></ul><sub id='ZUaap'></sub></form><legend id='ZUaap'></legend><bdo id='ZUaap'><pre id='ZUaap'><center id='ZUaap'></center></pre></bdo></b><th id='ZUaap'></th></span></q></dt></tr></i><div id='ZUaap'><tfoot id='ZUaap'></tfoot><dl id='ZUaap'><fieldset id='ZUaap'></fieldset></dl></div>

                      <bdo id='ZUaap'></bdo><ul id='ZUaap'></ul>
                        1. <legend id='ZUaap'><style id='ZUaap'><dir id='ZUaap'><q id='ZUaap'></q></dir></style></legend>

                          <small id='ZUaap'></small><noframes id='ZUaap'>