0

iPad アプリで XCode 5 と iOS 7 を使用しています。ユーザーが選択した行インデックスを保存しようとしています。-didSelectRowAtIndexPath では、次のコードを使用して行をマークします。

//  initialize singleton
SingletonSelectedCellIndexes *selectedCellIndexes = [SingletonSelectedCellIndexes sharedSelectedCellIndexes];  //  initialize

//  get the cell that was selected
UITableViewCell *theCell = [tableView cellForRowAtIndexPath:indexPath];

if ([[tableView cellForRowAtIndexPath:indexPath] accessoryType] == UITableViewCellAccessoryCheckmark) {
    [(NSMutableSet *)selectedCellIndexes addObject:indexPath];
}

シングルトンへの addObject でこのエラーが発生するのはなぜですか?:

「SingletonSelectedCellIndexes」の目に見える @interface がセレクター「addObject:」を宣言していません

シングルトン (NSMutableSet) を定義するコードは次のとおりです。

//++++++++++++++++++++++++++++++++++++++++++++++++++++
//--  SingletonSelectedCellIndexes
@implementation SingletonSelectedCellIndexes  {

}

@synthesize selectedCellIndexes;  //  rename

//  sharedSelectedCellIndexes
+ (id)sharedSelectedCellIndexes  {

static dispatch_once_t dispatchOncePredicate = 0;
__strong static id _sharedObject = nil;
dispatch_once(&dispatchOncePredicate, ^{
    _sharedObject = [[self alloc] init];
});

return _sharedObject;
}

-(id) init {
self = [super init];
if (self) {
    selectedCellIndexes = [[NSMutableSet alloc] init];
}
return self;
}

@end

更新- .h ファイルは次のとおりです。

//--  singleton: selectedCellIndexes
@interface SingletonSelectedCellIndexes : NSObject  {
}
@property (nonatomic, retain) NSMutableSet *selectedCellIndexes;

+ (id)sharedSelectedCellIndexes;
@end
4

1 に答える 1

1

回答する前に、SingletonSelectedCellIndexes クラスの .h ファイルを表示する必要があります。

ただし、.m ファイルには addObject メソッドが表示されないため、.h ファイルにも表示されないに違いありません。

クラスのメソッドを呼び出したい場合は、そのメソッドを宣言して実装する必要があります。

于 2013-09-21T21:52:02.320 に答える