Obj C:通过方法调用将对象的名称从一个类传递到另一个类
如何从一个类方法传递对象名称以使用另一类方法?假设调用其他类方法的类称为 class2,另一个类称为 class1。
class2 不需要了解有关 class1 对象的任何信息。因此,如果在 class2 方法内部调用类似的方法:
int idNum = [class1 getidNum:@"blockKind1" coord:tileCoord];
class1 的方法将能够以某种方式解释该对象名称。我知道这不对,只是举个例子。
根据要求当前“class2”接口:
@interface HeroClass : CCLayer {
DebugZoneLayer * debugZoneLayer;
CCSprite *_heroSprite;
CCSpriteBatchNode *_heroSpriteSheet;
CCAction *_heroSpriteFlyAction;
NSMutableArray *_collisPushPoints;
@public int _collisPushPointsNums;
@public float _travelRectCenterPointX;
@public float _travelRectCenterPointY;
NSMutableArray *_travelRectCenterPoints;
@public float _travelRectSteps;
/* amount of spacing in px between each center point
of a rect that checks collision detection */
@public int _rectCheckRes;
@public int _speed;
@public float _heroRectLookAhead;
@public CGPoint _vel;
@public CGRect _travelRectForTiles;
}
How do you pass the name of an object from one class method to use another class method? Say if the class that calls the other classes method is called class2 and the other is class1.
class2 is not required to know anything about class1's object. So if inside a class2 method something like this was called:
int idNum = [class1 getidNum:@"blockKind1" coord:tileCoord];
class1's method would be able to interpret that object name somehow of one of its own. I know that isn't right, just an example.
Current "class2" interface as requested:
@interface HeroClass : CCLayer {
DebugZoneLayer * debugZoneLayer;
CCSprite *_heroSprite;
CCSpriteBatchNode *_heroSpriteSheet;
CCAction *_heroSpriteFlyAction;
NSMutableArray *_collisPushPoints;
@public int _collisPushPointsNums;
@public float _travelRectCenterPointX;
@public float _travelRectCenterPointY;
NSMutableArray *_travelRectCenterPoints;
@public float _travelRectSteps;
/* amount of spacing in px between each center point
of a rect that checks collision detection */
@public int _rectCheckRes;
@public int _speed;
@public float _heroRectLookAhead;
@public CGPoint _vel;
@public CGRect _travelRectForTiles;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
键值编码?
Key Value Coding?