0
votes

I am trying to load a View including a UITableView from a nib by using code:

class HintTable:UIView, UITableViewDataSource, UITableViewDelegate{
var searchResults = Array<String>()
let delegate:MovableAnnotationDelegate
@IBOutlet var myTableView:UITableView!

init(frame: CGRect, delegate:MovableAnnotationDelegate) {
    self.delegate=delegate
    super.init(frame: frame)
    loadViewFromNib ()
}

required init?(coder aDecoder: NSCoder) {
    self.delegate=InArrivoHDViewController.sharedDetailController()
    super.init(coder: aDecoder)
    loadViewFromNib ()
}

func loadViewFromNib() {
    NSBundle.mainBundle().loadNibNamed("HintTableView", owner: self, options: nil)
    self.myTableView.backgroundColor=UIColor(red:0.2890625, green:0.75390625, blue:0.3046875, alpha:0.5)
    self.backgroundColor=UIColor(red:0.2890625, green:0.75390625, blue:0.3046875, alpha:0.5)
    print("myTableView %@", self.myTableView);
    self.myTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

}
}

Yet it crashes without any hint whatsoever on command:

NSBundle.mainBundle().loadNibNamed("HintTableView", owner: self, options: nil)

In the Xib I set the class as File's owner instead of getting it in the identity inspector. I am also quite unclear about how to access the tableView, as the IBOutlet seems unwired.

This is a crashlog:

Last Exception Backtrace: 0 CoreFoundation
0x182b3cf48 exceptionPreprocess + 124 1 libobjc.A.dylib
0x197fe7f80 objc_exception_throw + 56 2 CoreFoundation
0x182b3cc08 -[NSException raise] + 12 3 Foundation
0x1839b8014 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 268 4
UIKit 0x1883e3a4c -[UIView(CALayerDelegate) setValue:forKey:] + 184 5 UIKit 0x188596794 -[UIRuntimeOutletConnection connect] + 124 6 CoreFoundation 0x182a669cc -[NSArray makeObjectsPerformSelector:] + 232 7 UIKit
0x18859517c -[UINib instantiateWithOwner:options:] + 1748 8 UIKit
0x188597408 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 224 9 inArrivoHD
0x10023218c 0x100074000 + 1827212 10 inArrivoHD
0x100231bf8 0x100074000 + 1825784 11 inArrivoHD
0x100231d2c 0x100074000 + 1826092 12 inArrivoHD
0x10024ec34 0x100074000 + 1944628 13 inArrivoHD
0x100250678 0x100074000 + 1951352 14 UIKit
0x1880d0098 -[UIViewController loadViewIfRequired] + 996 15 UIKit
0x18818f580 -[UINavigationController _layoutViewController:] + 72 16 UIKit 0x18818f458 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 416 17 UIKit 0x18818e6a0 -[UINavigationController _startTransition:fromViewController:toViewController:] + 144 18 UIKit 0x18818e244 -[UINavigationController _startDeferredTransitionIfNeeded:] + 868 19 UIKit 0x18818de6c -[UINavigationController __viewWillLayoutSubviews] + 60 20 UIKit 0x18818ddd4 -[UILayoutContainerView layoutSubviews] + 208 21 UIKit 0x1880cb7ac -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 644 22 QuartzCore 0x1878cab58 -[CALayer layoutSublayers] + 148 23 QuartzCore 0x1878c5764 CA::Layer::layout_if_needed(CA::Transaction*) + 292 24 QuartzCore
0x1878c5624 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32 25 QuartzCore 0x1878c4cc0 CA::Context::commit_transaction(CA::Transaction*) + 252 26 QuartzCore 0x1878c4a08 CA::Transaction::commit() + 512 27 QuartzCore
0x1878be0f8 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80 28 CoreFoundation
0x182af3bd0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 32 29 CoreFoundation 0x182af1974 __CFRunLoopDoObservers + 372 30 CoreFoundation 0x182a20cc0 CFRunLoopRunSpecific + 416 31 UIKit
0x18813e1c8 -[UIApplication _run] + 460 32 UIKit
0x188138ffc UIApplicationMain + 204 33 inArrivoHD
0x1002cc3c0 0x100074000 + 2458560 34 libdyld.dylib
0x19882a8b8 start + 4

1
Provide exact error that is causing a crashGrzegorz Krukowski
I wish I could, in that case I would probably been able to correct myself. Unfortunately it silently crashes on the appDelegate. I was planning to have it crashes on the device to be reported on Quincykit, sometimes more useful than the Xcode debugger, but I have a corrupted table I am now repairing.Fabrizio Bartolomucci
Did you try addding exception breakpoint to catch that ? Also it should drop details in consoleGrzegorz Krukowski
I added the crashlog to my posting. Unfortunately it leaves nothing in the console. As for the exception breakpoint, I just added it and see what comes out.Fabrizio Bartolomucci
Unfortunately the exception breakpoint is totally ignored. The crash keep on appearing in the @ApplicationMainFabrizio Bartolomucci

1 Answers

-1
votes

I ended up inserting the view in the main ViewController of the Storyboard and assigning the delegate and source appropriately to the View.