【发布时间】:2011-08-18 00:03:26
【问题描述】:
如何将对象的名称从一个类方法传递给另一个类方法?假设调用其他类方法的类称为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;
}
【问题讨论】:
-
我不明白。那个“对象名称”是什么?
-
class1 有一个名为 blockKind1 的对象,但 class2 只想通过使用该对象名称进行方法调用从 class1 返回一个 int。
-
@user:“object”是指“ivar”吗?
@interface class1 : NSObject { int blockKind1; } ... @end -
@user:只需显示您当前的
@interface。 -
@user:我看不到任何与 blockKind1 或 tileCoord 相关的内容
标签: objective-c object methods