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