【发布时间】:2016-09-29 11:44:09
【问题描述】:
在我的自定义 UITableViewCell 中,我正在做这样的事情。
-(void)checkHeight
{
if (self.frame.size.height < self.expandedHeight) {
self.lblReasontitle.hidden=YES;
}
else
{
self.lblReasontitle.hidden=NO;
}
}
-(void)watchFrameChanges
{
if (!isObserving) {
[[NSNotificationCenter defaultCenter] addObserver:self forKeyPath:@"frame" options: (NSKeyValueObservingOptionNew |NSKeyValueObservingOptionInitial) context:nil];
isObserving=true;
}
}
-(void)ignoreFrameChanges
{
if (isObserving) {
[[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"frame"];
}
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
if ([keyPath isEqualToString:@"frame"]) {
[self checkHeight];
}
}
但我遇到了这个异常。
由于未捕获的异常 NSUnknownKeyException 导致应用程序终止,原因:[addObserver: forKeyPath:@"frame" options:5 context:0x0] 被发送到“frame”属性不符合 KVC 的对象。
我不知道那个异常是什么以及如何解决它。 请帮我。 谢谢
【问题讨论】:
标签: ios uitableview nsnotificationcenter addobserver