複数のメソッドを持つクラスがあります。このクラスを別のオブジェクトからインスタンス化し、それらのメソッドを呼び出すことができます。新しいメソッドを追加すると、クラス内の別のメソッドまたは別のクラスから呼び出すことができません。パラメータを削除するとメソッドが表示されますが、再度追加するとメソッドが表示されません。私はこことインターネットを検索し、クラスをインポートしていることと、メソッドが .h ファイルで定義されていることを確認しました。何が問題なのか途方に暮れています。
インターフェース:
@interface npcgGetCharacterData : NSObject
@property (strong, nonatomic) NSFetchedResultsController *fetchedResults;
@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
@property BOOL debug;
- (NSMutableString *)getRandomRace;
- (NSMutableString *)getRandomAlignment;
- (int)getRandomLevel;
- (NSMutableString *)getRandomNPCType;
- (NSMutableString *)getRandomNPCClass:(NSString *)entityClassType;
@end
実装:
#import "npcgGetCharacterData.h"
#import "RaceEntity+Properties.h"
#import "AlignmentEntity+Properties.h"
#import "NPCTypeEntity+Properties.h"
@implementation npcgGetCharacterData
@synthesize fetchedResults, managedObjectContext, debug;
- (NSMutableString *)getRandomRace {
NSString *randomRace = [NSString alloc];
NSArray *resultsArray;
NSInteger intCount;
RaceEntity *raceEntity;
[self setupFetchedResultsController:@"RaceEntity" entityName:@"raceName" entityWhere:@"raceName != 'Any Race'"];
debug = NO;
[self performFetch];
resultsArray = [fetchedResults fetchedObjects];
intCount = [resultsArray count];
raceEntity = [resultsArray objectAtIndex:arc4random() % intCount];
randomRace = raceEntity.raceName;
self.fetchedResults = nil;
return randomRace.mutableCopy;
}
- (NSMutableString *)getRandomAlignment {
NSString *randomAlignment = [NSString alloc];
NSArray *resultsArray;
NSInteger intCount;
AlignmentEntity *alignmentEntity;
[self setupFetchedResultsController:@"AlignmentEntity" entityName:@"alignmentName" entityWhere:@"alignmentName != 'Any Alignment'"];
debug = NO;
[self performFetch];
resultsArray = [fetchedResults fetchedObjects];
intCount = [resultsArray count];
alignmentEntity = [resultsArray objectAtIndex:arc4random() % intCount];
randomAlignment = alignmentEntity.alignmentName;
self.fetchedResults = nil;
return randomAlignment.mutableCopy;
}
- (NSMutableString *)getRandomNPCType {
NSString *randomNPCType = [NSString alloc];
NSArray *resultsArray;
NSInteger intCount;
NPCTypeEntity *npcTypeEntity;
[self setupFetchedResultsController:@"NPCTypeEntity" entityName:@"npcTypeName" entityWhere:@"npcTypeName != 'Any Type'"];
debug = NO;
[self performFetch];
resultsArray = [fetchedResults fetchedObjects];
intCount = [resultsArray count];
npcTypeEntity = [resultsArray objectAtIndex:arc4random() % intCount];
randomNPCType = npcTypeEntity.npcTypeName;
self.fetchedResults = nil;
return randomNPCType.mutableCopy;
}
- (NSMutableString *)getRandomNPCClass:(NSString *)entityClassType {
NSString *randomNPCClass = [NSString alloc];
return randomNPCClass.mutableCopy;
}
- (int)getRandomLevel {
int intRandomLevel = 0;
intRandomLevel = (NSInteger)arc4random_uniform(20) + 1;
return intRandomLevel;
}
- (void)setupFetchedResultsController:(NSString *)entityType entityName:(NSString *)entityName entityWhere:(NSString *)entityWhere{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityType];
if (entityWhere != nil) {
[request setPredicate:[NSPredicate predicateWithFormat:entityWhere]];
}
NSSortDescriptor *entityGroup = [[NSSortDescriptor alloc] initWithKey:entityName ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *entityNameSort = [[NSSortDescriptor alloc] initWithKey:entityName ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
request.sortDescriptors = [NSArray arrayWithObjects:entityGroup, entityNameSort, nil];
self.fetchedResults = [[NSFetchedResultsController alloc]
initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
}
- (void)performFetch {
if (self.fetchedResults) {
if (self.fetchedResults.fetchRequest.predicate) {
if (self.debug) NSLog(@"[%@ %@] fetching %@ with predicate: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResults.fetchRequest.entityName, self.fetchedResults.fetchRequest.predicate);
} else {
if (self.debug) NSLog(@"[%@ %@] fetching all %@ (i.e., no predicate)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResults.fetchRequest.entityName);
}
NSError *error;
[self.fetchedResults performFetch:&error];
if (error) NSLog(@"[%@ %@] %@ (%@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [error localizedDescription], [error localizedFailureReason]);
if (self.debug) {
NSLog(@"Number of Objects = %i", [[self.fetchedResults fetchedObjects] count]);
}
} else {
if (self.debug) NSLog(@"[%@ %@] no NSFetchedResultsController (yet?)", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
}
}
@end
呼び出し方法。これは別のオブジェクトからのものです:
- (IBAction)GenerateNPCClick:(id)sender {
npcgGenerateAttribute *nga = [npcgGenerateAttribute alloc];
npcgGetCharacterData *ngc = [npcgGetCharacterData alloc];
ngc.managedObjectContext = self.managedObjectContext;
int intValue = 0;
NSMutableString *textViewHolder = [NSMutableString alloc];
for (NSInteger i = 0; i < 6; i++) {
intValue = nga.generate4D6;
if (i == 0) {
textViewHolder = [NSMutableString stringWithFormat:@"%d", intValue];
} else {
[textViewHolder appendString:@"\n"];
[textViewHolder appendString:[NSMutableString stringWithFormat:@"%d", intValue]];
}
}
NSMutableString *strRace = ngc.getRandomRace;
[textViewHolder appendString:@"\n"];
[textViewHolder appendString:@"Race: "];
[textViewHolder appendString:strRace];
NSMutableString *strAlignment = ngc.getRandomAlignment;
[textViewHolder appendString:@"\n"];
[textViewHolder appendString:@"Alignment: "];
[textViewHolder appendString:strAlignment];
int intLevel = ngc.getRandomLevel;
[textViewHolder appendString:@"\n"];
[textViewHolder appendString:@"Level: "];
[textViewHolder appendString:[NSMutableString stringWithFormat:@"%d", intLevel]];
NSMutableString *strNPCType = ngc.getRandomNPCType;
[textViewHolder appendString:@"\n"];
[textViewHolder appendString:@"NPC Type: "];
[textViewHolder appendString:strNPCType];
[ngc getRandomNPCClass:@"TestString"];
self.textViewMessageSpace.text = textViewHolder;
}
問題を引き起こしているメソッドは getRandomNPCClass メソッドです。他の getRandom メソッドはすべて機能しています。
エラー メッセージを含めるのを忘れました: プロパティ 'getRandomNPCClass' はタイプ 'npcgGetCharacterData *' のオブジェクトではありません。別のオブジェクトから呼び出そうとすると、これが発生します。
助けてくれてありがとう。