我只是想知道是否有可能在我解雇一个 ViewController 之后立即将其推送到一个 ViewController。
我一直在尝试:
-(void)dismiss{
//send information to database here
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"Dismiss completed");
[self pushtoSingle:post_id];
}];
}
-(void)pushtoSingle:(int)post_id{
Single1ViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"SingleView"];
svc.post_id = post_id;
svc.page = 998;
[self.navigationController pushViewController:svc animated:YES];
}
还有这个:
-(void)dismiss{
//send information to database here
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"Dismiss completed");
Single1ViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"SingleView"];
svc.post_id = post_id;
svc.page = 998;
[self.navigationController pushViewController:svc animated:YES];
}];
}
但没有成功。 View 已成功关闭,但推送从未初始化。 是否有另一种已知的解决方法?
最佳答案
是的,我想通了。我只是在将 ViewController B 解除到 A 之后发布了一个通知,然后在 A 中收到通知并推送到 C..
在 B 中解雇:
[self dismissViewControllerAnimated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushToSingle" object:nil userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:post_id1] forKey:@"post_id"]];
}];
在 A 中接收:
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToSingle:) name:@"pushToSingle" object:nil];
}
-(void)pushToSingle:(NSNotification *)notis{
NSDictionary *dict = notis.userInfo;
int post_id = [[dict objectForKey:@"post_id"] intValue];
NSLog(@"pushing to single");
Single1ViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"SingleView"];
svc.post_id = post_id;
svc.page = 998;
[self.navigationController pushViewController:svc animated:YES];
}
谢谢,小杰!
关于objective-c - dismissViewControllerAnimated :completion: Push to another ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11390612/