In my program, I am trying to set the property ‘frame’ of an object stored in an NSMutableArray. When I try to set the frame of the object, my program receives the signal ‘SIGABRT’ with the message ‘__[NSCFNumber setFrame:]: unrecognized selector sent to instance 0x6a8d960.’ How do I fix this?
for (int i = 0; i < [computerHand count]; i++)
{CardView* card = [computerHand objectAtIndex:i]; card.frame = CGRectMake(10+70*i, 340, 60, 85);}
declaration of computerHand:
@property(retain) NSMutableArray* computerHand;
population of computerHand
-(void) addCardToHand:(NSMutableArray *)hand
{
[hand addObject:[cards objectAtIndex:0]];
NSLog(@"%@", [[cards objectAtIndex:0]class]);
[cards removeObjectAtIndex:0];
}
Note- The NSLog prints ‘__NSCFNumber’ to the console.
code for deck population
-(void) createDeck : (UIView *)view
{
cards = [[NSMutableArray alloc]initWithCapacity:52];
for (int i = 0; i <= 4; i++)
{
for(int j = 0; j <= 13; j++)
{
CardView* card = [[CardView alloc] initWithFrame:CGRectMake(view.center.x - 60/2, view.center.y - 85/2, 60, 85) value:j];
[cards addObject:card];
[view addSubview:card];
}
}
for(int i =0; i<= 52; i++)
{
NSLog(@"%@", [cards objectAtIndex:i]);
}
}
Note: the NSLog command correctly prints a CardView object to the console, but then prints __NSCFNumber when trying to access it from a different scope.
Any help is appreciated.
The issue is you’re not getting the correct object out of your array. If you break right after you get your
CardViewout of your array, and print the description in the console, it’s a string and not actually aCardView. There are two things you need to do.In your for loop you can do this to make sure you are only setting frames on CardViews:
You still want to make sure that you’re actually only putting in CardViews though, but this is a way to debug.