如何在 swift 中单击按钮时从故事板调用 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)
可以试试这个:
// Register Xib
let abcViewController = ABCViewController(nibName: "abcViewController", bundle: nil)
// Present VC "Modally" style
self.present(abcViewController, animated: true, completion: nil)
将 ID 设置为 abcViewController
与相同的 class 名称
谢谢
@Mujtaba 修复屏幕不显示全屏的问题转到故事板中的视图控制器并将演示样式更改为全屏
我是新手 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
与相同的 class 名称
谢谢
@Mujtaba 修复屏幕不显示全屏的问题转到故事板中的视图控制器并将演示样式更改为全屏