KVO上的iphone..如何从ViewWillExample方法调用observeValueForKeyPath方法?
以下是我的资料KVO上的iphone..如何从ViewWillExample方法调用observeValueForKeyPath方法?,iphone,key-value-observing,Iphone,Key Value Observing,以下是我的资料 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([object isKindOfClass:[UIAccelerometer class]]) { NSNumber *interfaceValue = [change objectForKey:NS
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([object isKindOfClass:[UIAccelerometer class]]) {
NSNumber *interfaceValue = [change objectForKey:NSKeyValueChangeNewKey];
UIInterfaceOrientation toInterfaceOrientation = [interfaceValueintValue];
//here is my code....
}
如果我理解正确,您希望在keyValue更改时执行某些代码,并且您还希望在viewwillbeen中执行此代码。不要试图通过编程方式触发KVO方法,只需创建一个单独的函数,您可以从两个位置调用该函数:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
[self myKeyValueObservationMethod];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self myKeyValueObservationMethod];
}
- (void)myKeyValueObservationMethod {
// here is my code....
}
如果我完全没有注意到,请编辑您的问题,并在您对问题的解释中添加更多细节