gpt4 book ai didi

ios - Swift 5 - 导航页面

转载 作者:行者123 更新时间:2023-11-28 13:27:42 25 4
gpt4 key购买 nike

我刚开始使用 Swift 5,必须更新我的应用程序。我用....

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home")
self.present(vc, animated: true, completion: nil)

将用户从登录屏幕推送到主应用程序,但更新后的外观如下所示(iPhone 当前处于暗模式)...

一些问题。这个功能到底叫什么?我该如何去操纵它?假设我想删除它,因为现在如果用户在主应用程序中,他们可以向下滑动并返回到登录屏幕,这肯定会导致问题。

enter image description here enter image description here

enter image description here

登录查看 Controller 代码

import UIKit
import Firebase
import RealmSwift

class StartViewController: UITableViewController, UITextFieldDelegate {

@IBOutlet weak var email: UITextField!
@IBOutlet weak var password: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

// Check if user is already logged-in so they don't have to sign-in again
checkUserSignIn()

// Setting textfield delegates so user can press enter and go to next textfield
self.email.delegate = self
self.password.delegate = self

let uid = Auth.auth().currentUser?.uid
print(uid)
print("printing the uid here")

}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

// Add a background view to the table view
let backgroundImage = UIImage(named: "startBackground")
let imageView = UIImageView(image: backgroundImage)
self.tableView.backgroundView = imageView
imageView.contentMode = .scaleAspectFill
}

// Check if user is already signed-in, if so push to main app
func checkUserSignIn() {
Auth.auth().addStateDidChangeListener({ (auth, user) in
if (user != nil) {
Database.database().reference().child("users").child((user?.uid)!).observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("user is logged in")
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home")
vc.modalPresentationStyle = .overCurrentContext
self.present(vc, animated: true, completion: nil)
}
})
}
})
}

@IBAction func login(_ sender: Any) {
if self.email.text == "" || self.password.text == "" {

//Alert to tell the user that there was an error because they didn't fill anything in the textfields because they didn't fill anything in

let alertController = UIAlertController(title: "Error", message: "Please enter an email and password.", preferredStyle: .alert)

let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)

self.present(alertController, animated: true, completion: nil)

} else {

Auth.auth().signIn(withEmail: self.email.text!, password: self.password.text!) { (user, error) in

if error == nil {
//Print into the console if successfully logged in
print("You have successfully logged in")

// Proceed To App
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "home") {
} else {
print("Problem sending user into nature app")
}
}

} else {

//Tells the user that there is an error and then gets firebase to tell them the error
let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)

let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)

self.present(alertController, animated: true, completion: nil)
}
}
}
}

@IBAction func createAccount(_ sender: Any) {
// Check user has entered text into fields
guard let email = email.text, email != "",
let password = password.text, password != ""

else {
// Throw alert message to user if fields are empty
let alert = UIAlertController(title: "Registration Error", message: "Please make sure you filled in all of the boxes to complete registration!", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(okAction)
present(alert, animated: true, completion: nil)

return
}

// Register a new user on Firebase
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in

// Throw registration error / Account could already exist
if let error = error {
let alert = UIAlertController(title: "Registration Error", message: error.localizedDescription, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
return
}

guard let userID = user?.user.uid else {
return
}

// Database reference
let databaseRef = Database.database().reference()
// Set user information to firebase data structure
let userInfo = fireUsersData(email: email, profPicString: "", uid: userID)
databaseRef.child("users").child(userID).updateChildValues(userInfo.getUserDictionary(), withCompletionBlock: { (err, databaseRef) in

let UserToAdd = realmUserData()
UserToAdd.email = email
UserToAdd.uid = userID
//UserToAdd.saveDataToRealm()

if err != nil {
// Throw error is problem completeting
let alert = UIAlertController(title: "Error", message: (err?.localizedDescription)! as String, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
})
})

// Dismiss keyboard
self.view.endEditing(true)

// Proceed To App
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "home") {
} else {
print("Problem sending user into nature app")
}
}
}
// END OF FILE
}

最佳答案

在展示你的 ViewController 之前给出这个选项:

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home")
vc.modalPresentationStyle = .overCurrentContext
self.present(vc, animated: true, completion: nil)

要忽略 didFinishLaunchingWithOptions 中的暗模式样式,请这样写:

 if #available(iOS 13.0, *) {
window?.overrideUserInterfaceStyle = .light
}

更新:将当前代码替换为:

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home") as! UITabBarController

UIApplication.shared.keyWindow?.rootViewController = vc

关于ios - Swift 5 - 导航页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58083905/

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