I created a test project in ios 8 beta 4 which as a main view controller and a second view controller created as a UIViewController subclass with a xib file.
I put a button on the main controller to present the second controller:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func testVCBtnTapped() {
let vc = TestVC()
presentViewController(vc, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I run the app and pressing the button presents the second controller - all is well
Moving to xcode beta 5, I run the app and when I press the button the screen goes black.
Since I know they messed with the init code, I tried putting in overrides to see it that would fix it:
class TestVC: UIViewController {
override init() {
super.init()
}
required init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder)
}
override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
Same problem. Changing the required and overrides in to all possible combinations accepted by xcode has no effect.
If I use the storyboard to create another controller and segue to it all is well.
Any ideas?
EDIT - New info
Apparently a swift beta 5 problem
I've had this problem recently, and my solution is to override the nibName method in baseviewController. My solution is as follows:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
init() {
super.init(nibName: nil, bundle: Bundle.main)
}
override var nibName: String? {
get {
if #available(iOS 9, *) {
return super.nibName
} else {
let classString = String(describing: type(of: self))
guard Bundle.main.path(forResource: classString, ofType: "nib") != nil else {
return nil
}
return classString
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With