I am trying to add a subview in a viewController
. To perform that I have created an xib
file and an associated class. The code of the associated class is given below:
import UIKit
@IBDesignable class CustomClassViewController: UIView {
@IBOutlet weak var myLabel: UILabel!
var Dummyview : UIView! //= UIView()
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init (coder aDecoder : NSCoder){
super.init(coder : aDecoder)!
setup()
}
func setup() {
Dummyview = loadViewFromNib()
Dummyview.frame = bounds
Dummyview.autoresizingMask = UIViewAutoresizing.FlexibleWidth
Dummyview.autoresizingMask = UIViewAutoresizing.FlexibleHeight
addSubview(Dummyview)
}
func loadViewFromNib() -> UIView {
let bundle = NSBundle(forClass : self.dynamicType)
let nib = UINib(nibName: "Custom View", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
It shows no Error before run the application but it crash when I run the application. The Error shows as below:
"Threat 1: EXC_BAD_ACCESS(code= 2, address= 0x7fff52776e88)"
super.init(coder : aDecoder)!
But no Errors in Output.
I have tried the solution provided in here and here but not worked.
What should I do? Any solution? Please let me know. Thanks in advance