Completion block for popViewController

后端 未结 18 1606
离开以前
离开以前 2020-12-04 06:43

When dismissing a modal view controller using dismissViewController, there is the option to provide a completion block. Is there a similar equivalent for

18条回答
  •  春和景丽
    2020-12-04 07:18

    Just for completeness, I've made an Objective-C category ready to use:

    // UINavigationController+CompletionBlock.h
    
    #import 
    
    @interface UINavigationController (CompletionBlock)
    
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated completion:(void (^)()) completion;
    
    @end
    
    // UINavigationController+CompletionBlock.m
    
    #import "UINavigationController+CompletionBlock.h"
    
    @implementation UINavigationController (CompletionBlock)
    
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated completion:(void (^)()) completion {
        [CATransaction begin];
        [CATransaction setCompletionBlock:^{
            completion();
        }];
    
        UIViewController *vc = [self popViewControllerAnimated:animated];
    
        [CATransaction commit];
    
        return vc;
    }
    
    @end
    

提交回复
热议问题