繁体   English   中英

如何在快速单击按钮时从故事板调用xib文件

[英]how to call xib file from storyboard on button click in swift

我是 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)
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)

@Mujtaba 修复屏幕问题未显示全屏转到故事板中的视图控制器并将演示样式更改为全屏在此处输入图片说明

可以试试这个:

// Register Xib
let abcViewController = ABCViewController(nibName: "abcViewController", bundle: nil)
// Present VC "Modally" style
self.present(abcViewController, animated: true, completion: nil)

将 ID 设置为abcViewController作为相同的类名

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM