gpt4 book ai didi

iphone - iOS - 如何删除应用程序窗口层次结构中的所有 ViewController?

转载 作者:可可西里 更新时间:2023-11-01 05:22:05 27 4
gpt4 key购买 nike

我的应用程序使用典型的身份验证方案,其中用户使用他的凭据登录服务器,服务器返回一个身份验证 token ,然后将其存储在本地客户端 (iPhone) 上。

现在存储的身份验证 token 不太可能但有可能随着时间的推移而失效。由于使用该无效 token 发出的每个请求都会失败,因此我想在第一次发生该故障时通过“将用户注销”应用程序来处理这个问题。注意:该请求可能在后台线程中发出,因为该应用会定期与服务器同步。

注销意味着:

  1. 删除本地存储的 token
  2. 删除用户存储的所有其他内容(在 Sqlite 中)
  3. 将用户“重定向”到登录 Controller

因此,用户可能正在查看应用内的某些内容,而 token 变得无效并开始注销过程。

由于所有内容都被删除(#2),向她提供登录 Controller 是不够的,因为在登录并关闭该 Controller 之后,之前的内容实际上已经不存在了。

为了防止这些副作用,我想完全删除层次结构中的所有 View Controller ,无论触发注销时它有多深。

所以我的问题是:

在呈现登录 Controller 之前“杀死”所有事件 Controller 的最佳方法是什么?

最佳答案

将您的 LoginViewController 分配给窗口的 rootViewController。这是文档中对 rootViewController 的描述。这听起来和您想要完成的完全一样。

The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.

关于iphone - iOS - 如何删除应用程序窗口层次结构中的所有 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19164278/

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