【问题标题】:Navigation Controller not accessible within UIStoryboardSegue class在 UIStoryboardSegue 类中无法访问导航控制器
【发布时间】:2015-08-13 05:08:36
【问题描述】:

我有一个自定义 UIStoryboardSegue 类,我正在尝试从导航控制器转换视图,以便我的导航栏保持不变。

目前,我正在向视图控制器展示:

self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, animated: false, completion: nil);

我想使用:

self.navigationController?.pushViewController(self.destinationViewController as! UIViewController, animated: false);

但是,我无法访问 Segue 类中的 navigationController 对象。有什么方法可以从此类中访问navigationController 变量吗?

【问题讨论】:

  • 要达到segue的superview,试试self.superview,为什么不self.superview.pushViewController(...)
  • @Lamasse:当我尝试这样做时,我收到一个错误,指出该类没有名为“superview”的成员。有什么想法吗?

标签: ios swift uinavigationcontroller uistoryboardsegue


【解决方案1】:

如果您的控制器是第一个,请尝试此操作,如果不是,请相应地更改它。

let nc = self.navigationController!.viewControllers!.first as destinationViewController

self.navigationController?.pushViewController(nc, animated: false)

【讨论】:

  • 但是我无法访问navigationController 变量,所以我无法以这种方式声明变量nc。你有其他方法来获取 navigationController 变量吗?
猜你喜欢
  • 2021-08-19
  • 2015-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多