簡體   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