“ [__ SwiftValue set]:无法识别的选择器已发送到实例”

问题描述 投票:0回答:1
我有七个标签。每个选项卡都可以正常工作,直到我选择另一个视图控制器,或者选择“ ...”。我完全困惑。我已经设置了所有可以想到的断点。例如,当我准备在其中一个控制器中进行监视时,似乎所有变量都已正确设置,但是一旦函数退出,应用程序便会崩溃,然后加载下一个视图控制器。断点始终是AppDelegate中的类AppDelegate语句。

发生了什么事?当我切换回使用AppDelegate的Objective-C版本时,一切都很好。我认为,某些东西正在释放或取消引用,我无法检测到。这是AppDelegate中UITabbarController的代码:

let tc: UITabBarController? = window?.rootViewController as? UITabBarController var items: [UIViewController]? = tc?.viewControllers //set tab titles... var i: Int = 0 for nav in items ?? [] { guard let nav = nav as? UINavigationController else { continue } let vc: UIViewController? = nav.viewControllers.first i += 1 switch i { case 1: vc?.title = NSLocalizedString(Globals.kBD_Everyday, comment: "Title for first tab") case 2: vc?.title = NSLocalizedString(Globals.kBD_People, comment: "Title for second tab") case 3: vc?.title = NSLocalizedString(Globals.kBD_Places, comment: "Title for third tab") case 4: vc?.title = NSLocalizedString(Globals.kBD_Tracks, comment: "Title for fourth tab") case 5: vc?.title = NSLocalizedString(Globals.kBD_Songs, comment: "Title for fifth tab") case 6: vc?.title = NSLocalizedString(Globals.kBD_Instruments, comment: "Title for sixth tab") case 7: vc?.title = NSLocalizedString(Globals.kBD_Sources, comment: "Title for last tab") default: break } } if Globals.my_IS_TEST != 0 { //log application document directory print("Version \(appVersionString ?? ""), Build: \(appBuildString ?? "")") print("\(AppDelegate.applicationDocumentsDirectory()!)") print("plist at \(plist)") } else { //remove data load items?.removeLast() tc?.viewControllers = items } //firstObject is a nav controller let tabView = tc?.viewControllers?.first as! UINavigationController cvc = tabView.viewControllers.first as? ContainerViewController cvc?.isThisDay = true

这是调试器的输出:2020-02-04 18:23:22.118721-0500 Fab4Everyday [78607:10435517]-[__ SwiftValue set]:无法识别的选择器已发送到实例0x604000110c102020-02-04 18:23:22.125943-0500 Fab4Everyday [78607:10435517]

*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ SwiftValue set]:无法识别的选择器已发送至实例0x604000110c10'*第一个调用堆栈:(

0 CoreFoundation 0x000000010680627e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x0000000106673b20 objc_exception_throw + 48 2 CoreFoundation 0x0000000106826fd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010680ac4c ___forwarding___ + 1436 4 CoreFoundation 0x000000010680cf78 _CF_forwarding_prep_0 + 120 5 UIFoundation 0x000000011b0cdf37 -[NSCoreTypesetter _NSFastDrawString:length:attributes:paragraphStyle:typesetterBehavior:lineBreakMode:rect:padding:graphicsContext:baselineRendering:usesFontLeading:usesScreenFont:scrollable:syncAlignment:mirrored:boundingRectPointer:baselineOffsetPointer:wantsTextLineFragments:drawingContext:] + 2621 6 UIFoundation 0x000000011b0cf388 -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:graphicsContext:forceClipping:attributes:stringDrawingOptions:drawingContext:wantsTextLineFragments:validatedAttributedString:firstNonRenderedCharacterIndex:foundSoftHyphenAtEOL:enginePathUsed:] + 1142 7 UIFoundation 0x000000011b0c9a67 __NSStringDrawingEngine + 5999 8 UIFoundation 0x000000011b0c64bf _NSStringDrawingCore + 173 9 UIFoundation 0x000000011b0cac82 -[NSAttributedString(NSExtendedStringDrawing) drawWithRect:options:context:] + 456 10 UIKitCore 0x00000001197b3ea4 -[UILabel _drawTextInRect:baselineCalculationOnly:] + 3783 11 UIKitCore 0x00000001197b0dc8 -[UILabel drawTextInRect:] + 1051 12 UIKitCore 0x00000001197b4169 -[UILabel drawRect:] + 71 13 UIKitCore 0x00000001198656f3 -[UIView(CALayerDelegate) drawLayer:inContext:] + 632 14 QuartzCore 0x0000000104fbb6bf -[CALayer drawInContext:] + 285 15 QuartzCore 0x0000000104e85743 CABackingStoreUpdate_ + 190 16 QuartzCore 0x0000000104fc40e9 ___ZN2CA5Layer8display_Ev_block_invoke + 53 17 QuartzCore 0x0000000104fbb042 -[CALayer _display] + 2022 18 QuartzCore 0x0000000104fcda80 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 502 19 QuartzCore 0x0000000104f14848 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324 20 QuartzCore 0x0000000104f49b51 _ZN2CA11Transaction6commitEv + 643 21 UIKitCore 0x000000011937a3f4 _UIApplicationFlushRunLoopCATransactionIfTooLate + 104 22 UIKitCore 0x000000011941d57a __handleEventQueueInternal + 6902 23 CoreFoundation 0x0000000106769471 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 24 CoreFoundation 0x000000010676939c __CFRunLoopDoSource0 + 76 25 CoreFoundation 0x0000000106768b74 __CFRunLoopDoSources0 + 180 26 CoreFoundation 0x000000010676387f __CFRunLoopRun + 1263 27 CoreFoundation 0x0000000106763066 CFRunLoopRunSpecific + 438 28 GraphicsServices 0x000000010ac59bb0 GSEventRunModal + 65 29 UIKitCore 0x0000000119380d4d UIApplicationMain + 1621 30 Fab4Everyday 0x00000001026efb3b main + 75 31 libdyld.dylib 0x000000010c2e7c25 start + 1 32 ??? 0x0000000000000001 0x0 + 1

)libc ++ abi.dylib:以类型为NSException的未捕获异常终止

我已将一个应用程序从Objective-C转换为Swift 5.1。最后一步是转换AppDelegate。在我转换AppDelegate之前,该应用程序运行良好。转换后,每个segue都会崩溃,并显示以下信息:...

ios objective-c swift crash uitabbarcontroller
1个回答
0
投票
我以我认为是荒谬的方式解决了这个问题。当我对许多功能进行了更改(简化等)时,我所做的一项更改是为每个视图/导航控制器提供一个故事板ID和恢复ID。现在一切都好了。
© www.soinside.com 2019 - 2024. All rights reserved.