块方法完成后执行方法 [英] Execute a method after the completion of a block method

查看:94
本文介绍了块方法完成后执行方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在左菜单中使用 RNFrostedSidebar .在关闭边栏时,下面的代码块正在执行

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);
    }
  }

在执行dismissAnimated方法后,我想运行一个代码来更新HomeViewController,该代码是

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

主线程检查器:在后台线程上调用的UI API:-[UIView界限]"

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

然后我尝试了这也具有与上述相同的错误.

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

推荐答案

您的问题是因为您没有在UI线程中更新ui.要解决此问题,请在主队列中调用dismissAnimated:completion:方法.

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];
    }];
  });
}

这篇关于块方法完成后执行方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆