Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift 4.1中添加子视图自致崩溃_Ios_Crash_Addsubview_Swift4.1_Xcode9.3 - Fatal编程技术网

Ios 在swift 4.1中添加子视图自致崩溃

Ios 在swift 4.1中添加子视图自致崩溃,ios,crash,addsubview,swift4.1,xcode9.3,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.lo

我有一个自定义视图,其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
        )

共享崩溃日志。。。!!!parentView.addSubview(self)将self替换为self。view@HarshalValanda我试过了。仍然崩溃。@YagneshDobariya,添加堆栈trace@sonu能否显示
numberofrowsin节:
方法?