0

I have a custom view whose init method is as below. This used to work fine in Xcode 9.1 with swift 4. Today I updated to Xcode 9.3 and set the project base to swift 4.1 and it started crashing in this init method.

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()
    }

Crash stack trace

   *** 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
        )
sonu
  • 41
  • 5
  • share crash log...!!! – Yagnesh Dobariya Apr 16 '18 at 06:32
  • parentView.addSubview(self) replace self to self.view – Harshal Valanda Apr 16 '18 at 06:33
  • @HarshalValanda, tried that. Still crashes. – sonu Apr 16 '18 at 06:36
  • @YagneshDobariya, added stack trace – sonu Apr 16 '18 at 06:39
  • @sonu Can you show `numberOfRowsInSection:` method? – trungduc Apr 16 '18 at 06:56
  • What is the exception message? You have tried to call a function on an object that doesn't have the function. The detail of the object and the function will be in the exception message. It appears that you have told the system that at object is a tableviewDataSource when it isn't so you get a crash when it tries to call `numberOfRowsInSection` – Paulw11 Apr 16 '18 at 06:57
  • @trungduc, it just returns count func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return playerInfo.count } – sonu Apr 16 '18 at 09:47
  • @Paulw11, I'm getting the exception message Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MySampleApp.MyScoreView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fec1541d0f0'. But the breakpoint never hits any of the tableview delegate methods it crashes during init at adding subview line. – sonu Apr 16 '18 at 09:52
  • That means you have set an instance of `MyScoreView` as a table view's data source, but that class doesn't implement the tableview data source method `numberOfRowsInSection` – Paulw11 Apr 16 '18 at 09:57

0 Answers0