我在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,我可以实现我的目标吗?
答案 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"];
}