6

So I have set up JASidePanels with a root controller which implements JASidePanelController and my left panel which is a different UIViewController.

My problem is the left panel only receives the viewWillAppear viewDidAppear/disappear and viewWillAppear and viewDid/WillLoad only once for the first time the user slides the centre panel away. From then on these callback functions do not get called again.

What is the best way or how should I respond to these events inside my left panel view controller.

4

1 回答 1

12

好的,我想通了。

有一个属性叫

@property (nonatomic, readonly) JASidePanelState state;

它声明: “面板的当前状态。使用 KVO 监控状态变化”

我可以通过以下方式监控 3 种状态变化:

JASidePanelCenterVisible = 1,
JASidePanelLeftVisible,
JASidePanelRightVisible

我现在对状态的 KVO 更改做出反应。在我左侧面板的 viewDidLoad 中,我有:

[self.sidePanelController addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:nil];

并接收我的状态变化:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
    if ([keyPath isEqual:@"state"]) {
        if ([change[@"new"] isEqual:[NSNumber numberWithInt:1]]) {
            NSLog(@"Saving settings");
        }
    }
}
于 2014-06-26T05:57:52.473 回答