当我尝试使用ApplicationshortcutItem
导航到视图控制器时,我的应用程序立即崩溃。
但是,我的其他应用程序快捷方式(1 viewcontroller
以上)不会显示此行为。
导航到相同的视图控制器确实有效,并且不会使其崩溃。
我的崩溃:
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
中显示视图控制器的方法:
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
正在运行。
该视图显示了一个tableview,并使用了一个全局变量'pressedYear',该变量在导航到viewController之前在viewController上设置。 我的app委托也设置了这个相同的变量。
我该如何解决这个问题?因为我无法清楚地看到它出错的地方