【问题标题】:advice on UIViewController hierarchy and flow关于 UIViewController 层次结构和流程的建议
【发布时间】:2023-03-25 17:44:01
【问题描述】:

我花了很多时间阅读苹果视图控制器编程,但仍然不知道如何为我的流程编写代码。

我正在使用 ViewController、PageViewController 和 Storyboard。

我的 rootViewController 是一个 ViewController 我想要两个 ViewController

  • 首先,PageViewController 显示教程页面,最后一页已注册 presentViewController 登录
  • secondViewController,ViewController是app的主要内容

如果用户在钥匙串中有令牌,将转到 secondViewController。 注册或登录后进入 secondViewController

我没有使用导航控制器。想知道这可以通过容器视图控制器来完成吗?

当前问题在 signupViewController self.parentViewController 是 pageViewController 但我无法获取 rootViewController,以关闭并添加 secondViewController

P/S 但在 loginViewController self.presentingViewController 我得到了 rootViewController!出乎我的意料..我想知道为什么???

【问题讨论】:

    标签: ios objective-c uiviewcontroller


    【解决方案1】:
    1. 在 AppDelegate 中将 secondViewController 设置为 UIWindow 的 rootViewController。 SecondViewController 包含基本视图内容,没有关于登录的数据,因此您可以尽快启动。
    2. 如果用户在钥匙串中有令牌,只需更新 SecondViewController 视图的登录状态。
    3. 如果用户在钥匙串中没有令牌,则在 SecondViewController 上显示 PageViewController,并显示一个 viewController 或只是 addSubview。在PageViewController之后,出现loginViewController,登录完成后,关闭loginViewController,更新SecondViewController视图,登录状态与步骤2相同

    【讨论】:

    • pageViewController 最后一页正在注册。问题是注册后我无法获取 rootViewController 或关闭 rootViewController。 pageViewController 显示 SignupViewController 不存在或添加子视图。通过委托协议将 ViewController 返回给 pageViewController
    • 在 loginViewController 中,只需执行[self dismissModalViewControllerAnimated:YES]
    【解决方案2】:

    你使用故事板,所以我假设你也会使用 segue。您的 PageViewController 可以作为入口点,与 secondViewController 有一个 segue。

    如果您在钥匙串中有令牌,您可以使用以下方式以编程方式执行转场:

    [self performSegueWithIdentifier: @"MySegue" sender: self];

    否则用户会留在 PageViewController 上以服务其原始流程。

    【讨论】:

    • 我创建了从 PageViewController 到 secondViewController 的 segue,但我无法从 SignupViewController 获取我的 pageViewController。因此我也不能在用户触摸按钮后执行 [self.parentViewController performSegueWithIndentifier:@"mySegue" sender:self]
    • 你会改变方向吗?即 secondViewController 作为入口点。如果 keychain 中没有 token,在成功注册后模态页面视图控制器和页面并使用 unwind segue?
    • 不,总是 rootViewController 到 pageView 到 secondView,或者 rootViewController 到 secondView 而已
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-06-03
    • 2012-01-27
    • 2016-06-27
    相关资源
    最近更新 更多