Swift:"Use of undeclared type" 尝试推送到现有视图控制器时
Swift: "Use of undeclared type" when trying to push to existing view controller
所以我试图以编程方式推送到情节提要上的现有视图控制器,但我正在使用未声明的类型:LoginViewController 即使我将情节提要 ID 设置为 LoginViewController 这是我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myButton: UIButton!
@IBAction func Button(_ sender: UIButton) {
if let ButtonImage = myButton.image(for: .normal),
let Image = UIImage(named: "ButtonAppuyer.png"),
UIImagePNGRepresentation(ButtonImage) == UIImagePNGRepresentation(Image)
{
let loginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.navigationController?.pushViewController(loginVC, animated: true)
} else {
print("OK")
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
提前致谢!
确保创建一个新的 class LoginViewController
继承自 UIViewController。
为此,转到 文件 菜单 > 新建 > 文件
在iOS选项卡中,选择Cocoa触摸Class
然后下一个
将 class 命名为 LoginViewController
,并使其成为 UIViewController
的子class
单击下一步,然后单击创建。这将向您的项目添加一个新文件,您稍后 could/should 自定义其内容。
在故事板的 Identity Inspector 选项卡中,确保将 class 名称和标识符设置为 LoginViewController
。
所以我试图以编程方式推送到情节提要上的现有视图控制器,但我正在使用未声明的类型:LoginViewController 即使我将情节提要 ID 设置为 LoginViewController 这是我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myButton: UIButton!
@IBAction func Button(_ sender: UIButton) {
if let ButtonImage = myButton.image(for: .normal),
let Image = UIImage(named: "ButtonAppuyer.png"),
UIImagePNGRepresentation(ButtonImage) == UIImagePNGRepresentation(Image)
{
let loginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.navigationController?.pushViewController(loginVC, animated: true)
} else {
print("OK")
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
提前致谢!
确保创建一个新的 class LoginViewController
继承自 UIViewController。
为此,转到 文件 菜单 > 新建 > 文件
在iOS选项卡中,选择Cocoa触摸Class
然后下一个
将 class 命名为 LoginViewController
,并使其成为 UIViewController
单击下一步,然后单击创建。这将向您的项目添加一个新文件,您稍后 could/should 自定义其内容。
在故事板的 Identity Inspector 选项卡中,确保将 class 名称和标识符设置为 LoginViewController
。