【问题标题】:Error: Argument passed to call that takes no arguments错误:传递给不带参数的调用的参数
【发布时间】:2018-01-06 17:19:32
【问题描述】:

我正在创建一个简单的登录注册应用程序。但是我遇到了一个错误,我不知道如何解决它,请帮助!这是我的代码:

//
//  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

【问题讨论】:

  • 顺便说一句,我正在使用包含 swift 4 的 xcode 9.2。

标签: ios swift firebase


【解决方案1】:

instantiateInitialViewController 接受无参数,它只是初始化情节提要的第一个视图控制器。您正在寻找instantiateViewController

let loggedInVC = storyboard.instantiateViewController(withIdentifier:"LoggedInVC") as! LoggedInVC

【讨论】:

    【解决方案2】:

    请勿使用此代码

    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)
        }
    

    查找第一行。您实例化需要内存的新 Main.Storyboard。使用已经在内存中的情节提要。

      func presentLoggedInScreen() {
       let loggedInVC = storyboard?.instantiateInitialViewController(withIdentifier:"LoggedInVC") as! LoggedInVC
       self.present(loggedInVC, animated: true, completion: nil)
    }
    

    【讨论】:

    • 嗨!感谢您的解决,但错误仍然存​​在,请问还有其他解决方法吗?
    • 在 presentLoggedInScreen() 上设置断点。在执行操作时检查函数是否调用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 2019-10-29
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    相关资源
    最近更新 更多