我正在尝试观察收藏笔记。这是代码:
-(void) registerNotesHeaderViewChangeNotification
{
[self.selectedVegetableGarden addObserver:self forKeyPath:@"notes" options:NSKeyValueObservingOptionNew | NSKeyValueChangeRemoval context:nil];
}
-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
MyVegetableGarden *vegGarden = (MyVegetableGarden *) object;
if([vegGarden.notes count] > 0)
{
self.tableView.tableHeaderView = [self createSharingView];
}
else
{
self.tableView.tableHeaderView = nil;
}
}
现在,我希望当我从 notes 集合中删除一个对象时,它应该触发 observeValueForKeyPath 方法。
[self.selectedVegetableGarden.notes removeObject:note];
目前,它没有开火!