【问题标题】:Obj C: Pass the name of an object from one class to another from method callObj C:通过方法调用将对象的名称从一个类传递给另一个类
【发布时间】: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


【解决方案1】:

Key Value Coding?

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

【讨论】:

  • 就是这样!谢谢.. 这是巨大的,将真正简化我的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-01
  • 2017-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多