我很难过。我的应用程序正在使用核心数据来管理玩家并匹配签入。我有两个类,我试图在用户从桌面视图中选择一个玩家时将玩家详细信息添加到匹配项中。
- (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;
}
我将checkInPlayer
属性设置为等效的selectedPlayer
属性时出错。
checkInPlayer
是CheckIn
的一类,具有以下属性:
@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
是Player
的一类,具有以下属性:
@interface Player : NSManagedObject
@property (nonatomic, retain) NSString * playerFirstName;
@property (nonatomic, retain) NSString * playerID;
@property (nonatomic, retain) NSString * playerLastName;
@property (nonatomic, retain) NSSet *playerCheckins;
@end
有什么想法吗?
完整错误:
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
答案 0 :(得分:2)
您说checkInPlayer
属于CheckIn
类,但您尝试访问仅在Player
课程中声明的属性。您需要在playerFirstName
课程中声明相同的属性(CheckIn
等),或者您需要将checkInPlayer
更改为Player
的实例} class。
更清楚的是,它看起来应该更像这样:
- (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;
}
答案 1 :(得分:0)
JJC说了什么。
'NSInvalidArgumentException',原因:' - [CheckIn setPlayerFirstName:]:
但是,CheckinClass
在playerFirstName
设置了firstName
,checkInPlayer.playerFirstName = selectedPlayer.playerFirstName;
只有一个属性。
你有:
checkInPlayer.firstName = selectedPlayer.playerFirstName;
应该是:
{{1}}