0
在Objective-C中,是否可以從靜態c函數的範圍內訪問實例變量和方法?我覺得我可能忽略了一個簡單的答案,但我對這種語言仍然很陌生。從c函數訪問實例變量和方法
考慮以下精簡代碼:
@implementation MyObject
static int ammoHitSensor(cpArbiter *arb, cpSpace *space, void *unused)
{
// Call an instance method - doesn't work, self is undefined!
[self doSomethingElse];
}
-(id)init
{
// Code to create graphics, etc, hidden for clarity
// Adding a collision handler in the Chipmunk physics library
cpSpaceAddCollisionHandler(space, COL_TYPE_AMMO, COL_TYPE_SENSOR, ammoHitSensor, NULL, NULL, NULL, NULL);
}
-(void)doSomethingElse
{
// Stuff happens
}
@end
所以我想一旦我進入的ammoHitSensor
範圍,我希望有某種方式重新進入的MyObject
範圍。到目前爲止,我還沒有運氣。
啊哈,那沒有的伎倆。謝謝! – 2010-10-13 15:52:24