Obj C:通过方法调用将对象的名称从一个类传递到另一个类

发布于 2024-11-05 01:18:49 字数 1018 浏览 1 评论 0原文

如何从一个类方法传递对象名称以使用另一类方法?假设调用其他类方法的类称为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热风软妹 2024-11-12 01:18:49

键值编码?

一种机制允许应用程序
访问对象的属性
间接通过名称(或键),而不是
而不是直接通过调用
访问器方法或作为实例
变量

Key Value Coding?

a mechanism allowing applications to
access the properties of an object
indirectly by name (or key), rather
than directly through invocation of an
accessor method or as instance
variables

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文