我正在创建一个简单的登录注册应用。但是我收到了一个错误,我不知道如何解决它,请帮忙!这是我的代码:
//
// ViewController.swift
// CHLogbook-Application
//
// Created by Timothy Dillan on 06/01/18.
// Copyright © 2018 TPINC. All rights reserved.
//
import UIKit
import FirebaseAuth
import Firebase
class ViewController: UIViewController {
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func createAccountTapped(_ sender: Any) {
if let email = emailTextField.text, let password = passwordTextField.text {
Auth.auth().createUser(withEmail: email, password: password, completion: { user, error in
if let firebaseError = error {
print(firebaseError.localizedDescription)
return
}
self.presentLoggedInScreen()
})
}
}
@IBAction func loginTapped(_ sender: Any) {
if let email = emailTextField.text, let password = passwordTextField.text {
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if let firebaseError = error {
print(firebaseError.localizedDescription)
return
}
self.presentLoggedInScreen()
})
}
}
func presentLoggedInScreen() {
let storyboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loggedInVC:LoggedInVC = storyboard.instantiateInitialViewController(withIdentifier:"LoggedInVC") as! LoggedInVC
self.present(loggedInVC, animated: true, completion: nil)
}
}
错误在withIdentifier
部分的这一行中,当我想运行它时,总是说“参数传递给不带参数的调用”:
let loggedInVC:LoggedInVC = storyboard.instantiateInitialViewController(withIdentifier:"LoggedInVC") as! LoggedInVC
答案 0 :(得分:3)
instantiateInitialViewController
使用无参数,它只是初始化故事板的第一个视图控制器。您正在寻找instantiateViewController
。
let loggedInVC = storyboard.instantiateViewController(withIdentifier:"LoggedInVC") as! LoggedInVC
答案 1 :(得分:0)
请勿使用此代码
<div id="modal_form">
<span>Some text in modal window</span>
</div>
查找第一行。您实例化需要内存的新Main.Storyboard。使用已经在内存中的故事板。
func presentLoggedInScreen() {
let storyboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loggedInVC:LoggedInVC = storyboard.instantiateInitialViewController(withIdentifier:"LoggedInVC") as! LoggedInVC
self.present(loggedInVC, animated: true, completion: nil)
}