我收到錯誤時「currentUpdateMethod」未申報(第一本函數中使用)。這個引用的變量currentUpdateMethod是頭文件中聲明的SEL類型的實例變量。因爲構建到模擬器並運行應用程序的工作如期,我相信我已經正確設置了一切。這個錯誤只在今天出現 - 我已經在設備上測試了幾天而沒有問題。我確實試圖清理和清理所有目標。我甚至在xcode中輸入變量名稱到文件中,併爲我自動完成變量。什麼可能導致設備編譯失敗這些變量,但不是模擬器的編譯?變量「未申報」只編譯爲設備
編輯:代碼如下。
超類:
#import "Deployable.h"
@interface Drawable : Deployable {
float currentDelta;
SEL currentUpdateMethod;
SEL currentAnimationMethod;
SEL currentBatchMethod;
float rotation;
}
- (id) init;
- (id) initWithActivationTime:(float)time;
- (int) updateWithDelta:(float)delta;
- (int) animate;
- (int) batch;
@end
那麼問題類:
#import "Drawable.h"
#import "Structures.h" //contains Vector2f declaration
@interface Player : Drawable {
Image *playerGraphic;
Vector2f position;
}
@property (nonatomic) Vector2f position;
- (id) initWithImage:(Image *)aGraphic andPosition:(Vector2f)aPosition;
- (void) setupInactiveState;
- (int) updateInactiveState;
- (int) animateInactiveState;
- (int) batchInactiveState;
- (void) setupActiveState;
- (int) updateActiveState;
- (int) animateActiveState;
- (int) batchActiveState;
@end
而且它的實施中,在錯誤拋出:
#import "Player.h"
#import "AIEngine.h"
@implementation Player
@synthesize position;
- (id) initWithImage:(Image *)aGraphic andPosition:(Vector2f)aPosition {
self = [super init];
if(self) {
playerGraphic = [aGraphic retain];
position = aPosition;
}
return self;
}
- (int) deployWithScene:(MainScene *)newScene {
[super deployWithScene:newScene];
[self setupInactiveState];
return 1;
}
- (void) setupInactiveState {
currentUpdateMethod = @selector(updateInactiveState); //'currentUpdateMethod' undeclared (first use in this function)
currentAnimationMethod = @selector(animateInactiveState); //'currentAnimateMethod' undeclared (first use in this function)
currentBatchMethod = @selector(batchInactiveState); //'currentAnimateMethod' undeclared (first use in this function)
}
- (void) setupActiveState {
currentUpdateMethod = @selector(updateActiveState); //'currentUpdateMethod' undeclared (first use in this function)
currentAnimationMethod = @selector(animateActiveState); //'currentAnimateMethod' undeclared (first use in this function)
currentBatchMethod = @selector(batchActiveState); //'currentBatchMethod' undeclared (first use in this function)
}
@end
只是重申一下,這六個錯誤只有建築設備時拋出。當我爲模擬器構建時,應用程序會生成並正常運行。
EDIT2:我切換到僅LLVM和誤差不拋出。我想找出問題的根源,而不是僅僅使用其他編譯器。有任何想法嗎?
你能告訴我們代碼嗎?你可能在某個地方有一些'#ifdef'宏,這可能會讓事情變得糟糕。 – BoltClock 2011-05-25 05:17:37
@BoltClock你真的認爲他會知道如何放置這樣的宏 - 但沒有意識到這是造成問題的原因?但我同意沒有代碼就沒有太多的事情可以做... – 2011-05-25 05:29:14
您使用的是GCC還是LLVM?海灣合作委員會有一些...有趣的錯誤與'受保護的'變量相關(見http://stackoverflow.com/questions/2778405/not-so-silly-objective-c-inheritance-problem-when-using-property-gcc- bug) – jv42 2011-05-25 13:09:25