1

I'm hacking the multicanvas example. I want to modify it in order to trigger some event whenever a new target view is displayed, i.e. on completion of the transitionFromView method.

I understand I could probably trigger some event from the completion block of the transitionFromView method, but I'm wondering if there's an existing callback mechanism in place for that.

I've tried implementing the following in the target canvas, but that doesn't seem to be called when switching views:

- (void)viewDidAppear{
    NSLog(@"my event");
}

Is there another callback I'm not aware of? Thank you.

jubl
  • 71
  • 4

1 Answers1

1

Try using the following methods:

-(void)viewDidAppear:(BOOL)animated {}    
-(void)viewDidDisappear:(BOOL)animated {}

NOTE: it's the :(BOOL)animated {} part that you were missing from your method names.

I downloaded the MultiCanvas example, and set the title for each of the canvases like so (changing the A to B and C):

-(void)setup {
    self.title = @"WorkSpaceA";
    //... the rest of the setup code as per the example
}

I also added two methods to each of the canvases:

-(void)viewDidAppear:(BOOL)animated {
    C4Log(@"%@ %@",self.title,NSStringFromSelector(_cmd));
}

-(void)viewDidDisappear:(BOOL)animated {
    C4Log(@"%@ %@",self.title,NSStringFromSelector(_cmd));
}

I then got the following logs:

//at launch
[C4Log] WorkSpaceA viewDidAppear:

//then I tapped button B
[C4Log] WorkSpaceB viewDidAppear:
[C4Log] WorkSpaceA viewDidDisappear:

//then I tapped button A
[C4Log] WorkSpaceA viewDidAppear:
[C4Log] WorkSpaceB viewDidDisappear:

//then I tapped Button C
[C4Log] WorkSpaceA viewDidAppear:
[C4Log] WorkSpaceB viewDidAppear:
[C4Log] WorkSpaceC viewDidAppear:
[C4Log] WorkSpaceA viewDidDisappear:
C4 - Travis
  • 4,502
  • 4
  • 31
  • 56