swift - 使用 ApplicationShortCut SIGTRAP 时崩溃

标签 swift crash crash-reports

当我尝试使用 ApplicationshortcutItem 导航到 View Controller 时,我的应用程序立即崩溃。 但是,我的另一个应用程序快捷方式(再添加 1 个 viewcontroller)并未显示此行为。 导航到同一个 View Controller 确实有效并且不会使其崩溃。

我的崩溃:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libswiftCore.dylib              0x000000010064e5dc 0x100510000 + 1304028
1   PayDay!                         0x000000010011166c 0x1000e0000 + 202348
2   PayDay!                         0x00000001001126a4 0x1000e0000 + 206500
3   UIKit                           0x0000000186c42f40 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 692
4   UIKit                           0x0000000186c430a8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
5   UIKit                           0x0000000186c321a8 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360
6   UIKit                           0x0000000186c47b74 -[UITableView _performWithCachedTraitCollection:] + 104
7   UIKit                           0x00000001869d87ac -[UITableView layoutSubviews] + 176
8   UIKit                           0x00000001868e80e4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 656
9   QuartzCore                      0x000000018428ea28 -[CALayer layoutSublayers] + 148
10  QuartzCore                      0x0000000184289634 CA::Layer::layout_if_needed(CA::Transaction*) + 292
11  UIKit                           0x00000001868fefa4 -[UIView(Hierarchy) layoutBelowIfNeeded] + 924
12  UIKit                           0x00000001869ad57c -[UINavigationController _layoutViewController:] + 1196
13  UIKit                           0x00000001869aaf54 -[UINavigationController _layoutTopViewController] + 228
14  UIKit                           0x00000001869c3cc0 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 728
15  UIKit                           0x00000001869c39ac -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 416
16  UIKit                           0x00000001869c36b4 -[UINavigationTransitionView _cleanupTransition] + 744
17  UIKit                           0x0000000186927b10 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 312
18  UIKit                           0x0000000186925d8c +[UIViewAnimationState popAnimationState] + 324
19  UIKit                           0x00000001869b711c -[UINavigationTransitionView transition:fromView:toView:] + 1792
20  UIKit                           0x00000001869acc30 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2696
21  UIKit                           0x00000001869abddc -[UINavigationController _startDeferredTransitionIfNeeded:] + 868
22  UIKit                           0x00000001869aba04 -[UINavigationController __viewWillLayoutSubviews] + 60
23  UIKit                           0x00000001869ab96c -[UILayoutContainerView layoutSubviews] + 208
24  UIKit                           0x00000001868e80e4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 656
25  QuartzCore                      0x000000018428ea28 -[CALayer layoutSublayers] + 148
26  QuartzCore                      0x0000000184289634 CA::Layer::layout_if_needed(CA::Transaction*) + 292
27  QuartzCore                      0x00000001842894f4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
28  QuartzCore                      0x0000000184288b24 CA::Context::commit_transaction(CA::Transaction*) + 252
29  QuartzCore                      0x000000018428886c CA::Transaction::commit() + 512
30  QuartzCore                      0x0000000184281dd8 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
31  CoreFoundation                  0x00000001817587b0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
32  CoreFoundation                  0x0000000181756554 __CFRunLoopDoObservers + 372
33  CoreFoundation                  0x0000000181680d30 CFRunLoopRunSpecific + 416
34  UIKit                           0x000000018695b834 -[UIApplication _run] + 460
35  UIKit                           0x0000000186955f70 UIApplicationMain + 204
36  PayDay!                         0x00000001001262dc 0x1000e0000 + 287452
37  libdyld.dylib                   0x000000018121e8b8 start + 4

Appdelegate 中显示 View Controller 的方法:

if let rootViewController = window?.rootViewController, let shortcutItemType = DGShortcutItemType(shortcutItem: shortcutItem) {
            rootViewController.dismissViewControllerAnimated(false, completion: nil)
            switch shortcutItemType {
            case .Message:
                let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let rootTabbarController = self.window?.rootViewController as! UITabBarController
                let firstNav = storyboard.instantiateViewControllerWithIdentifier("NavController") as! UINavigationController
                rootTabbarController.viewControllers![0] = firstNav
                let VC1 = storyboard.instantiateViewControllerWithIdentifier("PeriodeView")
                let VC2 = storyboard.instantiateViewControllerWithIdentifier("weekViewController")
                let VC3 = storyboard.instantiateViewControllerWithIdentifier("timesInsertViewController")
                firstNav.viewControllers.insert(VC1, atIndex: 1)
                firstNav.viewControllers.insert(VC2, atIndex: 2)
                firstNav.pushViewController(VC3, animated: false)
                break
            case .Time:
                let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let rootTabbarController = self.window?.rootViewController as! UITabBarController
                let firstNav = storyboard.instantiateViewControllerWithIdentifier("NavController") as! UINavigationController
                rootTabbarController.viewControllers![0] = firstNav
                let VC1 = storyboard.instantiateViewControllerWithIdentifier("PeriodeView")
                let VC2 = storyboard.instantiateViewControllerWithIdentifier("weekViewController")
                firstNav.viewControllers.insert(VC1, atIndex: 1)
                firstNav.pushViewController(VC2, animated: false)

                // Display an alert indicating the shortcut selected from the home screen.
                break
            }
        }

注意 case .Time 正在被调用。

该 View 显示一个 TableView ,并使用全局变量“pressedYear”,该变量在导航到 viewController 之前设置。 我的应用程序委托(delegate)也设置了这个完全相同的变量。

我该如何解决这个问题?因为我无法清楚地看到哪里出了问题

最佳答案

我已经能够找出问题所在。 由于我之前无法访问我的控制台(必须终止该应用程序),因此我更改了我的方案,并确保在 UIApplicationShortcut 上首次启动应用程序时我确实有权访问调试工具。

我做了以下事情: 我选择了我的设备并单击“编辑方案” enter image description here

这将显示以下结果: enter image description here

如果您按“等待可执行文件启动”,您可以完全终止该应用程序并仅在附加调试器的情况下运行它。

事实证明,我的应用程序卡住了,因为设置了一个变量,但随后神奇地设置为 "" 这导致应用程序崩溃,因为它无法转换 ""到一个Int。 我将不得不调查这个问题,但不是。已修复!

关于swift - 使用 ApplicationShortCut SIGTRAP 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36286126/

相关文章:

ios - 更改 UISearchbar 放大镜颜色、PlaceHolder 颜色和 X 颜色

ios - 使用 NSTimer 作为时钟运行定义的时间

ios - dynamicMemberLoookup ExpressibleByStringLiteral 参数 swift

ios NSPredicate 在创建时崩溃

ios - 这个崩溃日志是什么意思?无法符号化

ios - iPhone 崩溃日志没有正确符号化并且是双倍行距的

swift 2.2 : Optional Binding in a function

android - Android-应用程序崩溃

c++ - 为什么这段代码在 Linux 中运行良好但在 Windows 中却失败了?

ios - UIWeb View iOS 5 : WebKit/JavaScriptCore crash