objective-c - dismissViewControllerAnimated :completion: Push to another ViewController

标签 objective-c ios

我只是想知道是否有可能在我解雇一个 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/

相关文章:

ios - 如何使用 coreLocation 框架在 iOS 7 中计算速度

ios - 微软翻译 API-iOS

objective-c - iphone项目中的ipad旋转

ios - 获取 randomFloat 失败

ios - UIPanGestureRecognizer 无法识别平移小 Action (<3mm)

ios - 需要对 URL 进行 NSString 编码。 CFURLCreateStringByAddingPercentEscapes 破坏了我的字符串

ios - 如何使用 JavaScript 检测 iOS 设备的系统语言?

objective-c - 根据内容动态改变 UILabel 的高度

ios - 此 IP、站点或移动应用程序无权使用此 API key 。如何解决 iOS 应用程序的此问题?

objective-c - AFJSONRequestOperation 失败,因为 web 服务返回内容类型为 text/html 的 JSON