Reputation: 100
I am new in swift I want to call .xib file from storyboard on button click. I am using code like this but it crash because .xib file is not in storyboard
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "abcViewController") as! abcViewController
self.present(newViewController, animated: true, completion: nil)
this code
let newViewController = abcViewController(nibName: "abcViewController", bundle: nil)
self.present(newViewController, animated: true, completion: nil)
I just change line and now its work fine
let newViewController = abcViewController(nibName: "abcViewController", bundle: nil)
//self.present(newViewController, animated: true, completion: nil)
self.navigationController?.pushViewController(newViewController, animated: true)
Upvotes: 0
Views: 1276
Reputation: 529
@Mujtaba to fix the screen issue not showing full screen go to you view controller in the storyboard and change the presentation style to full screeen
Upvotes: 1
Reputation: 6213
let newViewController = abcViewController(nibName: "xibFileName", bundle: nil)
//If you want to present xib
self.present(newViewController, animated: true, completion: nil)
//If you want to push xib in navigation stack
self.navigationController?.pushViewController(newViewController, animated: true)
Upvotes: 1
Reputation: 1493
Can try this:
// Register Xib
let abcViewController = ABCViewController(nibName: "abcViewController", bundle: nil)
// Present VC "Modally" style
self.present(abcViewController, animated: true, completion: nil)
set the ID as abcViewController
as same class name
Thanks
Upvotes: 0