Evgeniy Kleban Evgeniy Kleban - 3 months ago 6x
Objective-C Question

Detect when user left viewController

I have controller (news screen), and i need to detect when user leave it. I tried

- (void)viewWillDisappear:(BOOL)animated

, but the problem is, when user tap share button (share in social networks etc.) that method triggers, but after sharing user is still in news screen, therefore its not work.

I also tried

-(void)willMoveToParentViewController:(UIViewController *)parent {

, but it also trigger when user first enter controller, which is wrong (i need to detect leaving only).

How can i detect when user leave controller, but not trigger when he enter "sharing" pop screen?


Check this it will help you.

UIActivityViewController *conroller=[[UIActivityViewController alloc] initWithActivityItems:@[@"Hello"] applicationActivities:nil];

You can handle the sharing thing in the completion here

[conroller setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError){

The completion will tell you that the activity was presented so you can handle the activities you want to handle in the completion like this

[self presentViewController:conroller animated:YES completion:^{
       NSLog(@"Activity Appeared"); //Same as viewWillDisappear

Hope this helps.