gpt4 book ai didi

ios - 从 didSelectRowAtIndexPath 发送到实例的无法识别的选择器

转载 作者:行者123 更新时间:2023-11-28 22:12:55 24 4
gpt4 key购买 nike

我被这个难住了。我的应用程序使用核心数据来管理玩家和比赛签到。我有这两个类,并尝试在用户从表格 View 中选择玩家时将玩家详细信息添加到比赛中。

- (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 属性时出现错误。

checkInPlayerCheckIn 的一个类,具有以下属性:

@interface CheckIn : NSManagedObject

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

selectedPlayerPlayer 的一个类,具有以下属性:

@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

最佳答案

您说您的 checkInPlayer 属于 CheckIn 类,但您正试图访问仅在您的 Player 类中声明的属性。您需要在 CheckIn 类中声明这些相同的属性(playerFirstName 等),或者您需要将 checkInPlayer 更改为是 Player 类的实例。

更清楚的是,它看起来应该更像这样:

- (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;
}

关于ios - 从 didSelectRowAtIndexPath 发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22465032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com