【问题标题】:Command failed due to signal: Segmentation fault: 11 (xcode 7)由于信号,命令失败:分段错误:11(xcode 7)
【发布时间】:2015-09-18 18:59:09
【问题描述】:

我将我的 xcode 6.4 更新为 xcode 7 (swift 2),现在我在我的 swift 项目中遇到了这个错误。经过几次尝试,我发现这是因为

func containerView() -> UIView {
    return self.view
}

这是 UIViewControllerTransitionCoordinatorContext 的协议,如果我删除该功能,则表示我的 ViewController 不符合此协议 UIViewControllerTransitionCoordinatorContext 。 xcode 7 建议我将函数更改为

func containerView() -> UIView? {
    return self.view
} 

然后它建议我删除问号。我真的不明白在这里做什么,有什么想法吗?

【问题讨论】:

    标签: xcode swift swift2 xcode7


    【解决方案1】:

    听起来您正在尝试做一些非法的事情。这是UIViewControllerTransitionCoordinatorContext上文档的前两句:

    符合 UIViewControllerTransitionCoordinatorContext 协议的对象提供有关正在进行的视图控制器转换的信息。 不要在你自己的类中采用这个协议。

    斜体字是我的。但这是为了强调我认为你试图违反的规则。你不可能成为 UIViewControllerTransitionCoordinatorContext。这是运行时提供的东西,而不是你。

    【讨论】:

    • 这是它在错误中所说的 **警告:'containerView()' 的结果与协议'UIViewControllerContextTransitioning' func containerView() -> UIView { ^ ? UIKit.UIViewControllerContextTransitioning:3:14: 注意:这里声明的要求'containerView()' @objc func containerView() -> UIView? ^ ** 这是代码github.com/MihaelIsaev/ECSwiftSlidingViewController/blob/master/… line 770
    • 你看我的回答了吗?您显然已经尝试让您的视图控制器采用 UIViewControllerTransitionCoordinatorContext 协议。你不能那样做。
    • UIViewControllerContextTransitioning 也是如此。文档说:“UIViewControllerContextTransitioning 协议的方法为视图控制器之间的过渡动​​画提供上下文信息。不要在您自己的类中采用此协议。”
    • 所以我需要删除 UIViewControllerContextTransitioning 委托?
    • 我没有说任何关于代表的事情。你没有显示足够的代码,但听起来你在说class ViewController : UIViewControllerTransitionCoordinatorContext 之类的东西,我说你不能这么说。但这只是一个猜测,因为您没有显示足够的代码。如果你想展示一些周围的代码,那就太好了。
    猜你喜欢
    • 1970-01-01
    • 2014-12-20
    • 2015-12-16
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 2017-02-06
    相关资源
    最近更新 更多