ios - 成功登录后无法关闭 UIViewController
问题描述
登录完成后,我正在努力从 NavigationStack 中关闭 UIViewController。
登录屏幕是一个 UIViewController 用这行代码呈现
let loginController = LoginController()
self.present(loginController, animated: true, completion: nil)
然后我运行此代码以通过 firebase 登录用户。
Auth.auth().signIn(withEmail: email, password: password) { (user, err) in
if let err = err {
print("Failed to sign in user with email", err )
}
//self.dismiss(animated: true, completion: nil)
let userProfileVC = UserProfileController()
let navController = UINavigationController(rootViewController: userProfileVC)
self.navigationController?.pushViewController(navController, animated: true)
}
如您所见,我尝试了 pushViewController 方法,还尝试了注释的 self.dismiss 方法?我所做的一切似乎都没有删除 loginController UIView 并将我带回 UINavigationController 主屏幕。谁能帮帮我,非常感谢。
解决方案
您可能需要打印您的视图堆栈并将其展示给我们以便更好地理解,但请尝试以下方法之一:
navigationController?.popViewController(animated: true)
或者
navigationController?.popToRootViewController(animated: true)
第一种方法将处理最近推送的视图控制器,而第二种方法将删除除您寻找的导航控制器“主屏幕”之外的所有内容。
推荐阅读
- javascript - 如何在 React 本机 FlatList 中加载两个状态,可以吗?
- java - 为什么 for 循环可以保存返回的布尔值但不能保存原始布尔值?
- r - 在 shinyapps.io RShiny 应用程序中使用 h2o 包
- kubernetes - 仅在 tidb 集群中由于 tidb pod 中的连接被拒绝而导致准备就绪问题失败
- python - 如何在 Python 中“堆叠”嵌套列表?
- influxdb-python - 如何从 Python 客户端为 InfluxDB 指定 range() 中的绝对时间?
- go - What errors are outputted to http.Server's ErrorLog struct field?
- python - 如何在字典中附加所有重复的字符串名称以使其成为对象列表?
- javascript - 为什么未定义元素数组上的`join()`在javascript中返回少1个元素?
- javascript - Whatsapp 只分享 window.location.search 的第一个参数