KVO를 사용하여 내 사용자 정의 tableviewcell (DHtableViewCell)의 값을 업데이트하려고합니다. 이 오류가 계속 발생합니다. 나는이 예외가있는 다른 사람들이 있다는 것을 알고 있지만 그들의 해결책은 도움이되지 않습니다.UITableViewCell copyWithZone 인스턴스로 전송 된 인식 할 수없는 선택자
-[DHTableViewCell copyWithZone:]: unrecognized selector sent to instance 0x1093958b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[DHTableViewCell copyWithZone:]: unrecognized selector sent to instance 0x1093958b0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101a40495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010179f99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101ad165d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000101a31d8d ___forwarding___ + 973
4 CoreFoundation 0x0000000101a31938 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001004cbee0 -[UILabel _setText:] + 126
6 GoalTasker328 0x0000000100001ae4 -[DHTableViewCell observeValueForKeyPath:ofObject:change:context:] + 276
7 Foundation 0x000000010139eea2 NSKeyValueNotifyObserver + 375
8 Foundation 0x00000001013a06f0 NSKeyValueDidChange + 467
9 Foundation 0x000000010136379c -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
있는 tableView를 구현하는 클래스 : cellForIndexPath가있는 tableview에서,
//.h
@interface DHTableViewCell: UITableViewCell
@property (strong, nonatomic) NSString *description;
@end
//*.m
@interface DHTableViewCell()
@property (weak, nonatomic) IBOutlet UILabel *detailsOfTask;
@end
- (void)awakeFromNib
{
// Initialization code
self.description = @"";
[self addObserver:self
forKeyPath:NSStringFromSelector(@selector(description))
options:NSKeyValueObservingOptionNew context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:NSStringFromSelector(@selector(description))]) {
[[self detailsOfTask] setText:(NSString *)object]; //**crashes here!!!!
}
}
그래서 코드가 작동하는 방식이 설명
라는 속성을 설정 cellForIndexpath 방법 내가 cell.description 속성을 설정합니다. 그런 다음 관찰자는 값이 변경된 것을보고 UILabel이 해당하는 텍스트를 업데이트합니다.나는 혼란 스럽습니다. 왜 copyWithZone을 호출하려고합니까? 이 문제를 어떻게 해결할 수 있습니까?