【问题标题】:Get a UIViewController to push to another controller获取 UIViewController 以推送到另一个控制器
【发布时间】:2014-12-07 00:41:21
【问题描述】:

我有一个模态视图控制器,如下所示:

[self presentViewController:photo animated:YES completion:nil];

因此照片是一个模态视图控制器,但是当它完成后,我想像这样推送到导航视图控制器:

[self dismissViewControllerAnimated:NO completion:^{

    // UINavigationController *nav = [[UINavigationController alloc] init];
    //nav.delegate = self;

    ProfilesViewController *profile = [[ProfilesViewController alloc] init];
    [_nav pushViewController:profile animated:YES];
}];

nav 是照片视图控制器中的一个属性,它也具有委托。仍然无法正常工作,所以我错过了什么?

【问题讨论】:

  • 等等!不要忘记 transitionFromViewController:toViewController:duration:options:animations:completion: 这可能是你所追求的。

标签: ios ios7 uiviewcontroller uinavigationcontroller


【解决方案1】:

不要把事情复杂化,因为它很容易完成,

在您展示照片模态视图控制器的视图控制器中,向它展示一个通知,像这样,

[self presentViewController:photo animated:YES completion:^{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToNextView:) name:@"someNotification" object:nil];
}];

然后像这样调用那个通知来关闭你的照片模态视图控制器

[self dismissViewControllerAnimated:YES completion:^{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"someNotification" object:nil];
}];

现在你可以像这样推送到另一个视图控制器

- (void) pushToNextView:(NSNotification *)notification {
    //If you want some value from your notification
    //NSDictionary *someValue = notification.object;
    [self.navigationController pushViewController:ProfilesViewController animated:YES];
}

【讨论】:

  • 好吧,所以我可以代替 object:nil,而不是 object:@"value",然后在 notification.object 中获取该值?
  • 是的,你可以。即使您也可以在 NSDictionary 中传递多个值。
  • 一个问题是它仍然会在推送之前回到主视图控制器。我见过没有这个的应用程序。
  • @chris,是的,没错。它应该去。但如果你真的不想显示main view controller,只需设置animated:NOpresentingdismissing 照片模型视图控制器。这不会为您提供相同的动画,但可能不会向您显示main view controller
  • 耳语应用找到了一种使用动画 = 是的方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-26
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 2013-05-24
相关资源
最近更新 更多