dismissViewControllerAnimated completion返回上一级传值objective-c

A–>跳转到B
A使用[self presentViewController:B animated:YES completion:NULL];跳转到B

B使用dismissViewControllerAnimated返回;

B代码:
[self dismissViewControllerAnimated:YES completion:^{
//关闭传值
[[NSNotificationCenter defaultCenter] postNotificationName:@“yiJiBackTo” object:self userInfo:[NSDictionary dictionaryWithObject:@“zhen” forKey:@“yiJiBackToVal”]];
}];

A代码:
在viewDidLoad方法中:NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleNotiChange:) name:@“yiJiBackTo” object:nil];

-(void)handleNotiChange:(NSNotification *)sender{
NSString *val = [[sender userInfo] valueForKey:@“yiJiBackToVal”];
if([val isEqualToString:@“zhen”]){
[self.navigationController popViewControllerAnimated:TRUE];
}
}

发布了138 篇原创文章 · 获赞 83 · 访问量 88万+

猜你喜欢

转载自blog.csdn.net/kunga0814/article/details/105343467