KVO を使用してカスタム tableviewcell (DHtableViewCell) の値を更新しようとしています。このエラーが発生し続けます。これと同じ例外が他にもあることは承知していますが、それらの解決策は役に立ちません。
-[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 を実装するクラスは、description というプロパティを設定します。
//.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!!!!
}
}
コードの仕組みは、tableview:cellForIndexpath メソッドで cell.description プロパティを設定することです。次に、オブザーバーは値が変更されたことを確認し、対応する UILabel のテキストを更新します。
私は困惑しています。copyWithZone を呼び出そうとしているのはなぜですか? どうすればこれを回避できますか?