0

I am using RNFrostedSidebar for leftmenu. While dismissing the sidebar, below block of code is executing

- (void)handleTap:(UIPanGestureRecognizer *)recognizer {
    [self dismissAnimated:YES completion:nil];
}

- (void)dismissAnimated:(BOOL)animated completion:(void (^)(BOOL finished))completion {

    void (^completionBlock)(BOOL) = ^(BOOL finished){
        [self rn_removeFromParentViewControllerCallingAppearanceMethods:YES];

        rn_frostedMenu = nil;

        if (completion) {
            completion(finished);
        }
    };

    if (animated) {
        CGFloat parentWidth = self.view.bounds.size.width;
        CGRect contentFrame = self.contentView.frame;
        contentFrame.origin.x = self.showFromRight ? parentWidth : -_width;

        CGRect blurFrame = self.blurView.frame;
        blurFrame.origin.x = self.showFromRight ? parentWidth : 0;
        blurFrame.size.width = 0;
        self.blurView.frame = blurFrame;
        self.blurView.alpha=0.1;

        [UIView animateWithDuration:self.animationDuration delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
                             self.viewForTable.frame = contentFrame;
                     }
                     completion:completionBlock];
    } else {
        completionBlock(YES);
    }
  }

After dismissAnimated method executed i want to run a code to update the HomeViewController, That code is

[self callNavBar];

-(void) callNavBar {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"adjustNavBar"
                                                    object:self];
}

i tried this solution, like adding the methods in queue and executing but i got exception as

"Main Thread Checker: UI API called on a background thread: -[UIView bounds]"

Then i tried this too got the same error as above.

trungduc
  • 11,926
  • 4
  • 31
  • 55
R. Mohan
  • 2,182
  • 17
  • 30

2 Answers2

1

Your problem is because you didn't update ui inside UI thread. To resolve it, call dismissAnimated:completion: method inside main queue.

- (void)handleTap:(UIPanGestureRecognizer *)recognizer {
  dispatch_async(dispatch_get_main_queue(), ^{
    [self dismissAnimated:YES completion:^(BOOL finished) {
      [self callNavBar];
    }];
  });
}
trungduc
  • 11,926
  • 4
  • 31
  • 55
  • if i do this, the second method is not executing after the completion of first method. I need to execute the second method 'callNavBar' in the completion of first block method. – R. Mohan Dec 08 '17 at 05:41
  • It's because in your question, you don't pass `callNavBar` method to completion block. I have updated my answer, you can check it again. – trungduc Dec 08 '17 at 06:01
  • Welcome @R.Mohan ;) – trungduc Dec 08 '17 at 06:07
-1

You can put the function as the completion handler here, instead of nil. That way it will run exactly when you want it.

It would look somewhat like this.

- (void)handleTap:(UIPanGestureRecognizer *)recognizer {
      [self dismissAnimated:YES completion:[self callNavBar]];
}
Rik
  • 1
  • 1
  • if i do like this then it is throwing error as "Sending 'void' to parameter of incompatible type 'void (^)(BOOL)'" – R. Mohan Dec 07 '17 at 12:32