my custom framework crashing 'Could not load NIB in bundle

ε祈祈猫儿з 提交于 2020-08-10 20:11:47

问题


I have a custom framework which includes one xib and a UIView class for the same.

when I connect my test app with the framework, it got crashed

 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/containers/Bundle/Application/10A66571-E4BA-4C82-BDCE-82DA8018CA1C/cam.app> (loaded)' with name 'scanner''
*** First throw call stack:
(0x1b318bab0 0x1b2ea5028 0x1b307b2fc 0x1b6efbb4c 0x1b6efc9e4 0x104902338 0x104901e68 0x104902078 0x1048a7c60 0x1048a74d8 0x1048a740c 0x1048a7514 0x1b6c29994 0x1b6c2e5c8 0x1b6c2e9b4 0x1b72a9c58 0x1b72a9354 0x1b72aa2f0 0x1b72bb4d4 0x1b74ab924 0x1b68729ac 0x1b726d370 0x1b726d700 0x1b6e08dec 0x1b8355ec0 0x1b837cb50 0x1b8360fa4 0x1b837c7e4 0x104cab27c 0x104cae9a4 0x1b83a3304 0x1b83a2fb0 0x1b83a351c 0x1b310724c 0x1b31071a0 0x1b310695c 0x1b31017d8 0x1b3101084 0x1bd34f534 0x1b7271670 0x1048a867c 0x1b2f80e18)
libc++abi.dylib: terminating with uncaught exception of type NSException

my framework code

import UIKit
import QKMRZScanner
public class scanner: UIView,QKMRZScannerViewDelegate {

    @IBOutlet var mrzScannerView: QKMRZScannerView!

    public func mrzScannerView(_ mrzScannerView: QKMRZScannerView, didFind scanResult: QKMRZScanResult) {
        print(scanResult.documentType)
    }

    override  init(frame: CGRect) {
        super.init(frame: frame)
        commitinit()
        mrzScannerView.delegate = self
    }


    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func commitinit(){
        Bundle.main.loadNibNamed("scanner", owner: self, options: nil)
        addSubview(mrzScannerView)
        mrzScannerView.frame = self.bounds
        mrzScannerView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
    }

    public func capture(){
        mrzScannerView.startScanning()
    }


}


my test app code below

import UIKit

import testfrme
class ViewController: UIViewController {

    @IBOutlet weak var tt: scanner!
    override func viewDidLoad() {
        super.viewDidLoad()
        let d = scanner()
        d.capture()

    }


}




can anyone help me to understand why its crashing ?? full source code of both available here testapp code framework code

updated:

new crash screenshot

UPDATED :

When i tried

        mrzScannerView = Bundle(for: QKMRZScannerView.self).loadNibNamed("QKMRZScannerView", owner: self, options: nil)


am getting below error !enter image description here]3

My xib connections look like this


回答1:


Make sure, that your scanner views Nib is exactly called "scanner".
Don't set your nibs TopView to type "scanner". Instead set filesOwner to "scanner".
Add a subview to your nib, set this views class to "QKMRZScannerView".
Connect this view to your @IBOutlet var mrzScannerView

Load your views nib like this:

func commitinit() {  
    let nib = UINib(nibName: String(describing: self), bundle: Bundle(for: type(of: self))) 

    guard let view = nib.instantiate(withOwner: self, options: nil).first as? UIView else {
        fatalError("Failed to instantiate nib \(nib)")
    }
    self.addSubview(view)
    view.frame = self.bounds
    view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}



回答2:


in your commitinit func add these codes

let bundle = Bundle(identifier:"your Bundle ID") 
bundle?.loadNibNamed("your XIB file name", owner: self,options: nil)


来源:https://stackoverflow.com/questions/60164479/my-custom-framework-crashing-could-not-load-nib-in-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!