如何结束Next ViewController

时间:2017-12-08 06:57:00

标签: ios objective-c callback objective-c-blocks nsnotificationcenter

我在ViewController A中有以下块

dispatch_async(dispatch_get_main_queue(), ^{
    [self dismissAnimated:YES completion:^(BOOL finished) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"adjustNavBar"
                                                            object:self];
    }];
});    

执行' dismissAnimated'块方法正在调用NSNotificationCenter,ViewController B中的Observer正在执行以下代码

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                            selector:@selector(adjustNavBar)
                            name:@"adjustNavBar"
                            object:nil];
}

-(void)adjustNavBar {
    [self checkForPartialScroll];
}

执行上述代码后,它以ViewController A。

结尾

但是我想在ViewController B中结束这个过程。如何做到这一点,我正在尝试这个回调函数。

使用Delegates或Callbacks,我可以实现我的目标吗?

2 个答案:

答案 0 :(得分:1)

notification之前发布dismissviewcontroller

 [[NSNotificationCenter defaultCenter] postNotificationName:@"adjustNavBar" object:self];  

dispatch_async(dispatch_get_main_queue(), ^{
    [self dismissAnimated:YES completion:^(BOOL finished) {

    }];
}); 

如果不起作用,请尝试在mainthread中运行checkForPartialScroll

答案 1 :(得分:0)

将代码写在代码上方, HomeVC下一个VC& amp;的名称 @" HomeVC"你下一个VC的标识符

 dispatch_async(dispatch_get_global_queue(0, 0), ^{
  HomeVC *homeVC = (HomeVC *) [self.storyboard instantiateViewControllerWithIdentifier:@"HomeVC"];
    }