// 1。声明一个静态上下文:
static void *changePageContext = &changePageContext;
// 2。在viewDidLoad中一个强大的裁判的currentPreviewItemIndex属性添加自身作为观察员到您的QLPreviewController:
[self.previewController addObserver:self forKeyPath:@"currentPreviewItemIndex" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:changePageContext];
// 3。实施观察者方法:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if (context == changePageContext)
{
NSLog(@"newValue:%ld",(long)self.previewController.currentPreviewItemIndex);
}
else
{
// Any unrecognized context must belong to super
[super observeValueForKeyPath:keyPath
ofObject:object
change:change
context:context];
}
}
// 4。删除在viewWillDisappear观察员:
-(void)viewWillDisappear:(BOOL)animated
{
if (![[self.navigationController viewControllers] containsObject: self])
{
[self.previewController removeObserver:self forKeyPath:@"currentPreviewItemIndex"];
}
}
你喜欢这个问题的任何解决方案?我也面临类似的问题。如果你有解决方案,那么你可以在这里指导吗? – Vijay