Ios 如何在swift中单击按钮从故事板调用xib文件

Ios 如何在swift中单击按钮从故事板调用xib文件,ios,swift,storyboard,xib,Ios,Swift,Storyboard,Xib,我是swift新手,我想在点击按钮时从故事板调用.xib文件。 我正在使用这样的代码,但它崩溃了,因为.xib文件不在脚本中 let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) let newViewController = storyBoard.instantiateViewController(withIdentifier: "abcViewController") as! abcViewContr

我是swift新手,我想在点击按钮时从故事板调用.xib文件。 我正在使用这样的代码,但它崩溃了,因为.xib文件不在脚本中

 let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
 let newViewController = storyBoard.instantiateViewController(withIdentifier: "abcViewController") as! abcViewController
 self.present(newViewController, animated: true, completion: nil)
此代码

 let newViewController = abcViewController(nibName: "abcViewController", bundle: nil)
 self.present(newViewController, animated: true, completion: nil)
像这样的屏幕

我刚换了线路,现在一切正常

 let newViewController = abcViewController(nibName: "abcViewController", bundle: nil)
 //self.present(newViewController, animated: true, completion: nil)

 self.navigationController?.pushViewController(newViewController, animated: true)
你可以试试这个:

// Register Xib
let abcViewController = ABCViewController(nibName: "abcViewController", bundle: nil)
// Present VC "Modally" style
self.present(abcViewController, animated: true, completion: nil)
将ID设置为
abcViewController
作为相同的类名

谢谢

您可以试试这个:

// Register Xib
let abcViewController = ABCViewController(nibName: "abcViewController", bundle: nil)
// Present VC "Modally" style
self.present(abcViewController, animated: true, completion: nil)
将ID设置为
abcViewController
作为相同的类名


感谢

@Mujtaba修复屏幕问题而不显示全屏转到情节提要中的“查看控制器”并将演示样式更改为“全屏显示”

@Mujtaba修复屏幕问题而不显示全屏转到情节提要中的“查看控制器”并将演示样式更改为“全屏显示”

未正确显示屏幕。添加评论,解释您的答案,阅读。我编辑的问题未正确显示屏幕。添加评论,解释您的答案,阅读。故事板内有xib吗?@Sailendra不,不在里面。如果我错了,请纠正我,你在故事板中有一个按钮,你想在按钮点击上加载一个xib,对吗?@Sailendra完成了谢谢你的时间。你在故事板中有一个xib吗?@Sailendra不,它不在里面。纠正我如果我错了,你在故事板中有一个按钮,你想在按钮点击上加载一个xib对吗?@Sailendra完成了谢谢你的时间。