Frage

I am using XCode 5 and iOS 7 on my iPad app. I am trying to save row indexes that have been selected by the user. In -didSelectRowAtIndexPath, I use this code to mark the rows:

//  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];
}

Why am I getting this error on addObject to the singleton?:

No visible @interface for 'SingletonSelectedCellIndexes' declares the selector 'addObject:'

This is the code that defines the singleton (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

UPDATE - here is the .h file:

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

+ (id)sharedSelectedCellIndexes;
@end
War es hilfreich?

Lösung

You need to show the .h file of your SingletonSelectedCellIndexes class before we can answer that.

Your .m file does not show an addObject method though, so I bet your .h file doesn't either.

If you want to call a method on a class, you need to declare and implement that method.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top