首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在将AppDelegate转换为Swift后,App崩溃,从Objective到[__SwiftValue set]:发送到实例的未识别的选择器

在将AppDelegate转换为Swift后,App崩溃,从Objective到[__SwiftValue set]:发送到实例的未识别的选择器
EN

Stack Overflow用户
提问于 2020-02-04 23:24:51
回答 1查看 155关注 0票数 1

我已经转换了一个应用程序从Objective到SWIFT5.1。最后一步是转换AppDelegate。在我转换AppDelegate之前,这个应用程序一直运行得很好。转换后,每个segue崩溃时:

"__SwiftValue set:发送到实例的不可识别的选择器“

我有七个标签。每个选项卡都能很好地工作,直到我切换到另一个视图控制器或如果我选择.更多。我完全不知所措。我已经设置了我能想到的每一个断点。例如,当我准备在其中一个控制器中使用segue时,所有变量似乎都被正确设置,但是一旦函数退出,应用程序在加载下一个视图控制器之前就会崩溃。断点总是AppDelegate中的类AppDelegate语句。

发生什么事了呢?当我切换到使用Objective版本的AppDelegate时,一切都很好。我想,有些东西被释放了,或者被取消了,我无法检测到。下面是UITabbarController在AppDelegate中的代码:

代码语言:javascript
运行
复制
    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 Fab4Everyday78607:10435517 -__SwiftValue set:未识别的选择器发送到实例0x604000110c10 2020-02-04 18:23:22.125943-0500 Fab4Everyday78607:10435517 *终止应用程序,原因是:'NSInvalidArgumentException',原因:‘_SwiftValue集:未识别的选择器发送到实例0x604000110c10’*第一次抛出调用堆栈:(

代码语言:javascript
运行
复制
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类型的完全例外终止

EN

回答 1

Stack Overflow用户

发布于 2020-02-09 16:50:45

我用我认为是荒谬的方法解决了这个问题。虽然我修改了许多函数,简化了等等,但我所做的一项改变是给每个视图/导航控制器一个故事板ID和恢复ID。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60066987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档