gpt4 book ai didi

swift - '在 NSBundle 包中找不到名为 'MainTabController' 的 Storyboard

转载 作者:搜寻专家 更新时间:2023-10-31 22:10:46 25 4
gpt4 key购买 nike

我收到的似乎无法修复的错误是

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainTabController' in bundle NSBundle

应用程序将构建并显示登录屏幕,但会立即崩溃并出现上述错误。

我已经尝试了其他与此类似的帖子中的所有以下内容,但没有成功。

  1. 删除 info.plist 文件中对 Storyboard的引用。当我执行此操作时,应用程序确实会启动,但我会看到黑屏,因为它没有加载 Storyboard 。
  2. 摆弄 Target Membership Main.storyboard。
  3. 从项目中删除 Storyboard,清理、运行,然后重新添加 Storyboard。
  4. 卸载 Xcode,重新安装 Xcode。
  5. 删除派生数据文件夹。

问题似乎出在我的presentMainScreen()方法上

func presentMainScreen(){
let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
let mainTabController = mainstoryboard.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController
mainTabController.selectedViewController = mainTabController.viewControllers?[1]
//let storyboard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
//let loggedInVC:LoggedInVC = storyboard.instantiateViewController(withIdentifier: "LoggedInVC") as! LoggedInVC
//self.present(loggedInVC, animated: true, completion: nil)
}

如果我注释掉 mainTabController 行,应用程序将完美运行,如果我取消注释 loggedInVC 行并注释掉 mainTabController 行,它也可以完美运行。

非常感谢任何建议。

下面是我的整个ViewController.swift代码和我工作区的截图

workspace

ViewController.swift

import UIKit
import FirebaseAuth

class ViewController: UIViewController {

@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
}

override func viewDidAppear(_ animated: Bool) {


if Auth.auth().currentUser != nil {
print("success")

self.presentMainScreen()
}
}

@IBAction func creatAccountTapped(_ 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
}
print("success")
self.presentMainScreen()

})

}
}

@IBAction func loginButtonTapped(_ 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
}

print("success")

self.presentMainScreen()

})

}

}

func presentMainScreen(){
let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
let mainTabController = mainstoryboard.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController
mainTabController.selectedViewController = mainTabController.viewControllers?[1]



//let storyboard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
//let loggedInVC:LoggedInVC = storyboard.instantiateViewController(withIdentifier: "LoggedInVC") as! LoggedInVC
//self.present(loggedInVC, animated: true, completion: nil)
}
}

最佳答案

您的 Storyboard的名称是什么?是 MainTabController.storyboard 还是 Main.storyboard

您正在尝试加载名为“MainTabController”的 Storyboard:

let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)

但之前您将其称为 Main.storyboard:

Fiddle with the Target Membership Main.storyboard.

此外,如果主选项卡 Controller 与您的登录 View Controller 位于同一 Storyboard中,那么您可以尝试使用此:

let mainTabController = self.storyboard.instantiateViewController(withIdentifier: "MainTabController")

关于swift - '在 NSBundle 包中找不到名为 'MainTabController' 的 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46496188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com