0
Anyidea爲什麼autocomplete在spaceScene屬性上不起作用?爲什麼不讓我的單身屬性自動完成?
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@class SpaceScene;
@interface SpaceSceneSingleton : NSObject
{
SpaceScene *spaceScene;
}
@property (assign) SpaceScene *spaceScene;
+(SpaceSceneSingleton*)sharedSpaceSceneSingleton;
-(void) addChildToSceneWith:(CCNode *) node andWithZindex: (int) zIndex;
-(void) runAction:(CCAction*) action;
-(void) setTouchIsEnabled:(BOOL) isEnabled;
-(void) removeChild: (CCNode *) child;
@end
#import "SpaceSceneSingleton.h"
@implementation SpaceSceneSingleton
@synthesize spaceScene;
static SpaceSceneSingleton* _sharedSpaceSceneSingleton = nil;
+(SpaceSceneSingleton*)sharedSpaceSceneSingleton;
{
@synchronized([SpaceSceneSingleton class])
{
if (!_sharedSpaceSceneSingleton)
[[self alloc] init];
return _sharedSpaceSceneSingleton;
}
return nil;
}
+(id)alloc
{
@synchronized([SpaceSceneSingleton class])
{
NSAssert(_sharedSpaceSceneSingleton == nil, @"Attempted to allocate a second instance of a singleton.");
_sharedSpaceSceneSingleton = [super alloc];
return _sharedSpaceSceneSingleton;
}
return nil;
}
-(id)init {
self = [super init];
if (self != nil) {
// initialize stuff here
}
return self;
}
-(void) addChildToSceneWith:(CCNode *) node andWithZindex: (int) zIndex
{
[self.spaceScene addChild:node z:zIndex];
}
-(void) runAction:(CCAction*) action
{
//[self.spaceScene add
}
-(void) setTouchIsEnabled:(BOOL) isEnabled
{
}
-(void) removeChild: (CCNode *) child
{
}
@end
我遇到的問題是我最終得到了循環引用。 Spacescene將自身分配給單身人士,因此它具有聲明的單身人頭。所以當我使用spacescene.h時,它會嚇壞了。 – Mel 2011-05-19 00:35:00
Ahhhhhh是的,我必須把它放在.m文件中 – Mel 2011-05-19 00:37:44