- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我以前使用过 NSNotifications,但这是我第一次尝试在 Cocoa Touch 中使用 KVO。
我的 UITableView Controller 在各种数据源之间切换,因此我将它们封装在不同的 UITableViewDataSource 子类中。我试图让我的 View Controller 观察这些 UITableViewDataSource 子类中的特定一个,并跟踪一个名为 loadState
的枚举,该枚举反射(reflect)了模型的加载状态。
我这样设置观察者:
[self.siteUpdatesDataSource addObserver:self
forKeyPath:@"loadState"
options:0
context:nil];
从调试器中我可以看到观察者已注册:
(gdb) po [self siteUpdatesDataSource]
<SiteUpdatesTableViewDataSource: 0x651e5a0>
Current language: auto; currently objective-c
(gdb) po [[self siteUpdatesDataSource] observationInfo]
<NSKeyValueObservationInfo 0x651dd70> (
<NSKeyValueObservance 0x651dd10: Observer: 0xc80f1e0, Key path: loadState, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x651dd90>
)
但是,我的viewController 中的observeValueForKeyPath 方法似乎从未被调用。我设置了一个断点,但即使我验证枚举已更改,也不会到达该断点。
- (void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
[self.tableView reloadData];
}
我很感激对我所缺少的东西的任何想法。
最佳答案
看不出有什么问题。您确定通过调用合成访问器或使用 KVC 或手动更改 loadState
属性(使用 willChangeValueForKey:
和 didChangeValueForKey:
通知更改)?
关于iphone - KVO - 观察枚举时未调用observeValueForKeyPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5277836/
当我的应用程序关闭时,主 Controller 类将其自身作为观察者从模型中删除,然后释放模型。像这样: - (void)dealloc { [theModel removeObserver:
我正在努力加深对这些机制的理解。我有一个启用触摸的 UIView,可以更新它自己的 center 属性。 我的理解是frame属性是center和bounds的合成函数。假设这是真的,我将一个观察者放
我正在尝试使用 KVO 来观察在我的页面 View Controller 的子内容 View Controller 的 ScrollView 中使用拖动时的更新变化,但是当应用程序启动时,它崩溃了说:
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我尝试使用 KVO 观察 UIView 子类上的属性,以便通过调用 drawRect: 触发绘制。在我的 initWithFrame: 中,我有这个: ... self.observedKeysTha
我以前使用过 NSNotifications,但这是我第一次尝试在 Cocoa Touch 中使用 KVO。 我的 UITableView Controller 在各种数据源之间切换,因此我将它们封装
我遇到了 KVO 问题,但我不知道它是什么。 我有一个可用于编辑或创建记录的屏幕。该记录由一个模型对象表示,该对象包含许多 NSString 类型的变量。 该字符串的 Controller 有一个实例
这个问题已经有答案了: In Cocoa KVO, why doesn't a change on a NSMutableArray proxy notify observers? (1 个回答) 已
当我想观察保留属性的变化时,我经常遇到这样的情况: @interface AnObserver {…} @property(retain) Foo *foo; 现在,当我想要设置观察时,我需要编写自己
我定义了两个具有相应 ivars 的属性并合成了它们: @property (nonatomic,copy) NSString* title; @property (nonatomic,copy) N
我试图掌握绑定(bind),并在 xcode 中设置了一个带有 CPTextView 的 CPWindow,并将窗口和 textview 绑定(bind)到它们各自的导出。 我有点卡住了,但是试图让
一定有一些我对 KVO 没有了解的地方,我试图通过滚动 UIScrollView 来滚动 UITableView,偏移量转换是正确的,但是 UITableView 滚动发生在 UIScrollView
我正在学习 MVVM,所以我在属性上添加了观察者 init(model: RegisterUserModel = RegisterUserModel()) { self.registerMo
我的 iPhone 应用程序核心数据属性的自定义访问器方法有问题。我想做的不仅仅是取出原始类型并返回它。我有一个可能的 activityTypes 的 NSSet,如果对象没有 primitiveTy
事情是这样的:我有一个单例监视设备的事件存储的变化。我有一个名为 events 的属性,我已将其包装在 eventsSignal RACSignal 中。 _eventsSignal = [RACAb
我得到的 iOS 应用 实体很少,它们由关系链接。举一个简单的例子,假设我们有这样的关系(一对多): company > person 我正在使用 xcode 4.6 和用于模型生成的核心数据建模工具
我在 iOS 应用程序中遇到 KVO 问题。我似乎无法正确处理。我正在尝试做什么: 我有一个 MenuViewController(可在左侧显示,如 facebook 应用程序)观察(并显示)全局值。
我试图通过以下代码从其他对象观察 UIViewController 的 KVO 的界面方向: [((UIViewController *)self.delegate) addObserver:self
我正在尝试使用 KVO 在 UILabel 和对象数据之间创建一个小型绑定(bind)系统。如果我的 UI 发生变化,我的数据也必须发生变化,如果我的数据发生变化,我的 UI 应该刷新以显示新值。 我
如果我在我的 iOS 应用程序上设置了本地通知,我将更新一个按钮。我想用 KVO 做到这一点,因为可以通过多种方式设置通知,所以我将无法轻松跟踪本地通知何时发生更改,否则。 我是这样设置的:
我是一名优秀的程序员,十分优秀!