在swift 4.1中添加subview self导致崩溃

时间:2018-04-16 06:30:32

标签: ios crash addsubview swift4.1 xcode9.3

我有一个自定义视图,其init方法如下所示。这曾经在使用swift 4的Xcode 9.1中正常工作。今天我更新到Xcode 9.3并将项目基础设置为swift 4.1并且它在这个init方法中开始崩溃。

init(frame: CGRect, detailDic: [[String:AnyObject]], parentView:UIView)
    {

        super.init(frame:frame)
        self.view = Utilities.loadViewFromNib(“MyScoreView", atIndex: 0, aClass: type(of: self),parent:self) as! UIView
        self.view.frame = frame
        self.view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
        self.view.isHidden = true
        finalScoreTable.register(UINib(nibName: “MyScoreTableViewCell", bundle: nil), forCellReuseIdentifier: "scoreCell")
        addSubview(self.view)
        parentView.addSubview(self) //Crashes here
        finalScoreTable.tableFooterView = UIView()
    }

崩溃堆栈跟踪

   *** First throw call stack:

        (
            0   CoreFoundation                      0x0000000104a471e6 __exceptionPreprocess + 294
            1   libobjc.A.dylib                     0x0000000103651031 objc_exception_throw + 48
            2   CoreFoundation                      0x0000000104ac8784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
            3   UIKit                               0x00000001066ea73b -[UIResponder doesNotRecognizeSelector:] + 295
            4   CoreFoundation                      0x00000001049c9898 ___forwarding___ + 1432
            5   CoreFoundation                      0x00000001049c9278 _CF_forwarding_prep_0 + 120
            6   UIKit                               0x0000000106626851 -[UITableView _numberOfRowsInSection:] + 62
            7   UIKit                               0x00000001068d5e5b -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2631
            8   UIKit                               0x00000001068dc219 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 487
            9   UIKit                               0x00000001068dc37f -[UITableViewRowData heightForTable] + 61
            10  UIKit                               0x00000001065d684e -[UITableView _updateContentSize] + 365
            11  UIKit                               0x0000000106605a8f -[UITableView _rebuildGeometry] + 66
            12  UIKit                               0x0000000106603583 -[UITableView didMoveToWindow] + 145
            13  UIKit                               0x0000000106581f55 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1718
            14  UIKit                               0x000000010659b73e -[UIScrollView _didMoveFromWindow:toWindow:] + 84
            15  UIKit                               0x0000000106581b98 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
            16  UIKit                               0x0000000106581b98 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
            17  UIKit                               0x0000000106574114 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
            18  UIKit                               0x0000000106573fea -[UIView(Hierarchy) _postMovedFromSuperview:] + 808
            19  UIKit                               0x0000000106584a2b -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1940
            20  MySampleApp                   0x0000000102649ec7 _T017MySampleApp14MyScoreViewCACSC6CGRectV5frame_Says10DictionaryVySSyXlGG13playerDetailsSo6UIViewC06parentF0tcfc + 4343
            21  MySampleApp                   0x0000000102648dc7 _T017MySampleApp14MyScoreViewCACSC6CGRectV5frame_Says10DictionaryVySSyXlGG13playerDetailsSo6UIViewC06parentF0tcfC + 87
            22  MySampleApp                   0x00000001026371b8 _T017MySampleApp22MainGameViewControllerC14showScoreAlertySo5TimerCF + 2200
            23  MySampleApp                   0x000000010263784c _T017MySampleApp22MainGameViewControllerC14showScoreAlertySo5TimerCFTo + 60
            24  Foundation                          0x00000001030bb4dd __NSFireTimer + 83
            25  CoreFoundation                      0x00000001049d6e64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
            26  CoreFoundation                      0x00000001049d6a52 __CFRunLoopDoTimer + 1026
            27  CoreFoundation                      0x00000001049d660a __CFRunLoopDoTimers + 266
            28  CoreFoundation                      0x00000001049cde4c __CFRunLoopRun + 2252
            29  CoreFoundation                      0x00000001049cd30b CFRunLoopRunSpecific + 635
            30  GraphicsServices                    0x000000010c816a73 GSEventRunModal + 62
            31  UIKit                               0x00000001064bc0b7 UIApplicationMain + 159
            32  MySampleApp                   0x00000001026580e7 main + 55
            33  libdyld.dylib                       0x00000001093d4955 start + 1
            34  ???                                 0x0000000000000001 0x0 + 1
        )

0 个答案:

没有答案
相关问题