【问题标题】:CSStickyHeaderFlowLayout swift receiver has no segue with identifierCSStickyHeaderFlowLayout swift接收器没有标识符的segue
【发布时间】:2015-10-27 02:43:42
【问题描述】:

我在 Swift 中将 CSStickyHeaderFlowLayout 用于 Parallax Header。 Xcode 7 迅捷 2.0 。

我测试了github swift demo。应用程序在切换到另一个视图控制器时崩溃。 日志说:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“Receiver () has no segue with identifier 'great1'

我还测试了 github object-c 演示代码,segue 工作正常。

我发现下面的代码有问题。它在 appDelegate.swift 中,用于存储库中的 swift 演示代码。有谁知道在有stickyParallaxHeader 时保持segue 工作的解决方案,如下图所示。

[] []

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        let stickyHeaderFlowLayout = CSStickyHeaderFlowLayout()
        let collectionViewController = CollectionViewController(collectionViewLayout: stickyHeaderFlowLayout)

        let window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window.rootViewController = collectionViewController
        window.makeKeyAndVisible()
        self.window = window
        return true
    }

下面是调试日志。

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<collectionviewmapdemo.CollectionViewController: 0x7fdbdb01d600>) has no segue with identifier 'great1''
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000108d50f65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000109116deb objc_exception_throw + 48
    2   UIKit                               0x0000000107919692 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
    3   collectionviewmapdemo           0x00000001051a6ba7 _TFC25collectionviewmapdemo24CollectionViewController14collectionViewfS0_FTCSo16UICollectionView24didSelectItemAtIndexPathCSo11NSIndexPath_T_ + 135
    4   collectionviewmapdemo           0x00000001051a6c2f _TToFC25collectionviewmapdemo24CollectionViewController14collectionViewfS0_FTCSo16UICollectionView24didSelectItemAtIndexPathCSo11NSIndexPath_T_ + 79
    5   UIKit                               0x0000000107f91eb0 -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 701
    6   UIKit                               0x0000000107fb2d51 -[UICollectionView touchesEnded:withEvent:] + 574
    7   UIKit                               0x0000000107988663 forwardTouchMethod + 349
    8   UIKit                               0x000000010798872c -[UIResponder touchesEnded:withEvent:] + 49
    9   UIKit                               0x0000000107988663 forwardTouchMethod + 349
    10  UIKit                               0x000000010798872c -[UIResponder touchesEnded:withEvent:] + 49
    11  UIKit                               0x0000000107c3dca5 _UIGestureRecognizerUpdate + 10289
    12  UIKit                               0x00000001077f7592 -[UIWindow _sendGesturesForEvent:] + 1137
    13  UIKit                               0x00000001077f8681 -[UIWindow sendEvent:] + 849
    14  UIKit                               0x00000001077aa752 -[UIApplication sendEvent:] + 263
    15  UIKit                               0x0000000107785fcc _UIApplicationHandleEventQueue + 6693
    16  CoreFoundation                      0x0000000108c7d0a1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x0000000108c72fcc __CFRunLoopDoSources0 + 556
    18  CoreFoundation                      0x0000000108c72483 __CFRunLoopRun + 867
    19  CoreFoundation                      0x0000000108c71e98 CFRunLoopRunSpecific + 488
    20  GraphicsServices                    0x000000010b240ad2 GSEventRunModal + 161
    21  UIKit                               0x000000010778b676 UIApplicationMain + 171
    22  collectionviewmapdemo           0x00000001051b555d main + 109
    23  libdyld.dylib                       0x0000000109c3f92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

【问题讨论】:

  • 您需要提供有关您正在使用的 Xcode 版本以及从哪个屏幕收到错误的更多信息。您需要调试并缩小问题范围。点击此处了解如何操作:raywenderlich.com/10209/my-app-crashed-now-what-part-1
  • 我正在使用 Xcode 7.0.1 swift 2 。我没有使用任何特定的代码,只是测试了来自 github 的演示代码作为第二个链接。您需要做的只是在 swift 2 演示代码之上添加一个视图控制器和新的 segue。然后错误弹出,应用程序崩溃。我还测试了同一存储库中的 obje-c 演示代码,在 segue 上没有问题。感谢您编辑我原来的问题。我学会了以后怎么做。
  • S 您需要使用有关您正在使用的工具的信息以及有关如何添加 segue 的一些代码来更新问题。显然,您添加 segue 的方式有问题
  • 我研究了很久。问题是应用程序 delegate.swift 中的一些代码来自存储库中的 swift 演示代码。请看我修改后的问题。
  • 您添加的 segue 有问题。检查转场标识符,如果可能,发送快照或说明您是如何创建转场的。

标签: ios swift uicollectionview segue identifier


【解决方案1】:

我终于解决了。

  1. 从项目中删除以上代码,保留

    func application(application: UIApplication, didFinishLaunchingWithOptions  launchOptions: [NSObject: AnyObject]?) -> Bool { return true }
    
  2. 确保布局类为CSStickyHeaderFlowLayout,见下图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    相关资源
    最近更新 更多