Question

I am stumped by this. My app is using core data to manage players and match check in. I have classes for both and am trying to add player details to a match when the user selects a player from a tableview.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Player *selectedPlayer = [self.fetchedResultsController objectAtIndexPath:indexPath];

    checkInPlayer.playerFirstName = selectedPlayer.playerFirstName;
    checkInPlayer.playerLastName = selectedPlayer.playerLastName;
    checkInPlayer.playerImage = selectedPlayer.playerImage;
}

I get the error when I set the checkInPlayer properties to their equivalent selectedPlayer properties.

checkInPlayer is a class of CheckIn and has these properties:

@interface CheckIn : NSManagedObject

@property (nonatomic, retain) NSDate * checkInTime;
@property (nonatomic, retain) NSString * firstName;
@property (nonatomic, retain) NSString * lastName;
@property (nonatomic, retain) NSSet *checkInPlayers;
@end

selectedPlayer is a class of Player and has these properties:

@interface Player : NSManagedObject

@property (nonatomic, retain) NSString * playerFirstName;
@property (nonatomic, retain) NSString * playerID;
@property (nonatomic, retain) NSString * playerLastName;
@property (nonatomic, retain) NSSet *playerCheckins;
@end

Any ideas?

Full error:

2014-03-17 15:54:17.989 League Manager[2507:60b] -[CheckIn setPlayerFirstName:]: unrecognized selector sent to instance 0x10963b240
2014-03-17 15:54:17.991 League Manager[2507:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CheckIn setPlayerFirstName:]: unrecognized selector sent to instance 0x10963b240'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101f3c495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000101a3c99e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000101fcd65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000101f2dd8d ___forwarding___ + 973
    4   CoreFoundation                      0x0000000101f2d938 _CF_forwarding_prep_0 + 120
    5   League Manager                      0x000000010000907b -[SelectPlayerTVC tableView:didSelectRowAtIndexPath:] + 379
    6   UIKit                               0x00000001006b15c2 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1312
    7   UIKit                               0x00000001006b16eb -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 221
    8   UIKit                               0x0000000100602100 _applyBlockToCFArrayCopiedToStack + 316
    9   UIKit                               0x0000000100601f71 _afterCACommitHandler + 460
    10  CoreFoundation                      0x0000000101f07dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    11  CoreFoundation                      0x0000000101f07d37 __CFRunLoopDoObservers + 391
    12  CoreFoundation                      0x0000000101ee7522 __CFRunLoopRun + 946
    13  CoreFoundation                      0x0000000101ee6d83 CFRunLoopRunSpecific + 467
    14  GraphicsServices                    0x0000000103f6df04 GSEventRunModal + 161
    15  UIKit                               0x00000001005e9e33 UIApplicationMain + 1010
    16  League Manager                      0x0000000100008433 main + 115
    17  libdyld.dylib                       0x00000001025d45fd start + 1
    18  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Was it helpful?

Solution

You say your checkInPlayer is of class CheckIn, yet you're trying to access properties that are only declared in your Player class. You'll either need to declare those same properties (playerFirstName, etc.) in your CheckIn class, or you need to change your checkInPlayer to be an instance of the Player class.

More clearly, it seems like it should look something more like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Player *selectedPlayer = [self.fetchedResultsController objectAtIndexPath:indexPath];

    checkInPlayer.firstName = selectedPlayer.playerFirstName;
    checkInPlayer.lastName = selectedPlayer.playerLastName;
    // No such property playerImage in the CheckIn class
    //checkInPlayer.playerImage = selectedPlayer.playerImage;
}

OTHER TIPS

What JJC said.

'NSInvalidArgumentException', reason: '-[CheckIn setPlayerFirstName:]:

In you CheckinClass you set playerFirstName, however, there is only a property for firstName.

You have:

checkInPlayer.playerFirstName = selectedPlayer.playerFirstName;

It should be:

checkInPlayer.firstName = selectedPlayer.playerFirstName;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top