我想使用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將名爲描述
//.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?我該如何解決這個問題?