일부 정보 : "House"와 "Treasury"의 두 가지 클래스가 있습니다. 둘 다 "구조체"라고하는 동일한 NSMutableArray 안에 있습니다. 하우스에는 "소유권"이라는 (int) 변수가 있습니다. for 루프 (100 루프)를 사용하여 한 지역에 주택과 국채를 생성합니다. 그런 다음 "구조체"를 반복하고 "소유권"정수를 할당하는 다른 루프가 있습니다. 그 루프에서는 (Houses * h 구조체)를 사용하지만 어떤 이유로 루프가 구조체의 "treasury"를 반복합니다. 재무부에는 소유권 변수가 없으므로 "setOwnership :"이 존재하지 않는다는 오류 메시지가 나타납니다. 나는 Cocos2D도 사용하고 있지만 중요하지 않습니다.Obj-C의 오류 "인스턴스로 보낸 인식 할 수없는 선택기"
// Variable
NSMutableArray *structures;
-(void) InitializeStructures
{
structures = [[NSMutableArray alloc]init];
for(int i = 0; i < initialColonies; i++)
{
House *h = [[House alloc]initWithFile:@"House.png"];
h.position = [self ReturnPositionOnMap]; // Returns a point in playing area
Treasury *t = [[Treasury alloc]initWithFile:@"Treasury.png"];
t.position = [self ReturnFarPointNearOrigin:h.position];
[structures addObject:h];
[self addChild:h z:1];
[structures addObject:t];
[self addChild:t z:1];
}
}
-(void) AssignOwnerships
{
for(House *h in structures)
{
// Simplified to only show where the error occurs.
h.ownership = [self ReturnID]; // Error occurs here.
// The error ONLY occurs when it is iterating through a Treasury.
}
}
구조 :
#import "CCSprite.h"
#import "ImportedGoods.h"
@interface Structure : CCSprite
{
int _integrity;
int _ID;
bool _occupied;
int _occupiedTimeLeft;
int _occupiedTimeMax;
Faction _faction;
}
@property(nonatomic, assign) int integrity;
@property(nonatomic, assign) int ID;
@property(nonatomic, assign) bool occupied;
@property(nonatomic, assign) int occupiedTimeLeft;
@property(nonatomic, assign) int occupiedTimeMax;
@property(nonatomic, assign) Faction faction;
@end
#import "Structure.h"
@implementation Structure
@synthesize integrity = _integrity;
@synthesize ID = _ID;
@synthesize occupied = _occupied;
@synthesize occupiedTimeLeft = _occupiedTimeLeft;
@synthesize occupiedTimeMax = _occupiedTimeMax;
@synthesize faction = _faction;
@end
하우스 :
#import "Structure.h"
#import "ImportedGoods.h"
@interface House : Structure
{
int _ownership;
}
@property(nonatomic, assign) int ownership;
@end
#import "House.h"
@implementation House
@synthesize ownership = _ownership;
@end
재무부 :
여기코드처럼 보이는 것입니다 난 그냥 다른있는 NSMutableArray는 "국채"라고하지만 가능하면 하나 개의 배열에 모든 것을 유지하고 싶습니다 만들 수 있다는 것을 알고
2011-11-07 18:45:29.016 Virtual World[788:10a03] -[Treasury setOwnership:]: unrecognized selector sent to instance 0x7498cc0
2011-11-07 18:45:29.022 Virtual World[788:10a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Treasury setOwnership:]: unrecognized selector sent to instance 0x7498cc0'
*** First throw call stack:
(0x17fb052 0x198cd0a 0x17fcced 0x1761f00 0x1761ce2 0xcbe33 0xc2193 0xc1e5f 0xc1a34 0x3fc81 0xc185e 0x176151d 0x1761437 0x39b25 0x36ee2 0x17fcec9 0x91f91 0x92adf 0x94991 0x869a30 0x869c56 0x850384 0x843aa9 0x27affa9 0x17cf1c5 0x1734022 0x173290a 0x1731db4 0x1731ccb 0x27ae879 0x27ae93e 0x841a9b 0xc07ef 0x20c5 0x1)
terminate called throwing an exception(gdb)
:
이 75,252,073,210는 오류입니다. "구조에서 하우스 * h"반복을 지정 했음에도 불구하고 여전히 국채로 반복되는 이유를 알고 싶습니다. 아래에 추가 정보 의견이 필요하면 추가하겠습니다. 감사합니다.
-1로 변경해야합니다. –
오, 고마워, 바로 지금 고칠거야. – Telinir
은 오류를 찾기 위해 더 많은 코드가 필요합니다. 아마도 재무부 수업 코드도 게시해야합니다. – Raptor