![](/img/trans.png)
[英]How to navigate from swift UI to storyboard on button click in swift UI?
[英]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)
可以試試這個:
// 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.