是否可以更改 tabBarItem 的根视图,以便点击会将您带到层次结构中的第二个视图?

发布于 2024-09-14 13:28:12 字数 150 浏览 4 评论 0原文

在 Obj-C/iOS 中。我们的 UI 设计需要一个包含注册或登录选项的初始屏幕。执行上述任一操作后,用户数据将保存到手机并显示 tabBarController。但是,点击底部的选项卡栏会将视图返回到“登录或注册”屏幕。是否可以更改 tabBarItem 层次结构中的根视图控制器?

In Obj-C / iOS. Our UI design calls for an initial screen with options to register or log on. After doing either of these, the user data is saved to the phone and a the tabBarController is shown. However, tapping on the tabBar at the bottom takes the view back to the "log on or register" screen. Is it possible to change the root view controller in a tabBarItem's hiearchy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱的那么颓废 2024-09-21 13:28:12

你所要做的就是有一个名为“LoginViewController”的 UIViewController 作为你的根控制器,但这个控制器没有 UITabBar 它只是一个带有 Login UIView 的控制器。并且还拥有 UITabBarController 及其所有内容集,但不包括登录,仅包含您的基本内容。

用户登录后,您将显示 UITabBarController 及其内容。

-(void) LoginUser {
      // Load UITabBarController
      YourAppDelegate *app = (YourAppDelegate*)[[UIApplication sharedApplication] delegate]; 
      [app.window addSubview:aTabBarController.view];
}

其中 app 是您的 *app 委托。

What you have to do is have a UIViewController called "LoginViewController" as your Root Controller but this controller does not have a UITabBar it's just a controller with the Login UIView. And also have your UITabBarController with all of its content set but don't include the Login just have your basic content.

After the user logs in you show the UITabBarController with its content.

-(void) LoginUser {
      // Load UITabBarController
      YourAppDelegate *app = (YourAppDelegate*)[[UIApplication sharedApplication] delegate]; 
      [app.window addSubview:aTabBarController.view];
}

where app is your *app Delegate.

你怎么这么可爱啊 2024-09-21 13:28:12

您无法更改根,但可以通过几种方法解决此问题。也许最简单的是在您的 viewWillAppear 方法中检查用户是否已登录,如果是,则立即加载(使用导航控制器,模态或仅根据您的应用程序的结构添加子视图),没有动画的常规登录视图,然后用户永远不会看到这种情况发生。 (您可以选择其他方式,仅在用户未登录时加载登录屏幕。)

You can't change the root, but you can solve this a few ways. Perhaps the simplest is in your viewWillAppear method check to see if the user is logged in, if so, immediately load (using navigation controller, modally or just add a subView depending on your app's structure), the regular logged in view without animation, then the user will never see that this happened. (You might choose to do it the other way, only load the login screen if the user is NOT logged in.)

浮萍、无处依 2024-09-21 13:28:12

我使用导航控制器而不是标签栏控制器,但我认为概念相似或相同。我不希望用户在登录后能够“追踪”到登录屏幕。

我将登录视图构建为模式视图,如果用户是,则在主应用程序视图控制器的 ViewDidLoad 中调用该模式视图未登录:

if (isUserLoggedIn == NO) {
    [self performSegueWithIdentifier:@"logInUserModalSegue" sender:self];
} 

主视图短暂加载,然后登录模式视图动画显示,覆盖所有内容。

当用户点击登录时,我检查凭据,然后关闭(或不关闭)模式控制器,如下所示:

if (logInStatus == YES) {
    [[self presentingViewController] dismissViewControllerAnimated:YES
                                                        completion:NO];
    } else {
    self.errorDisplay.text = @"Sorry, there was an error logging in.";
}

I am using a navigation controller instead of a tab bar controller, but the concept I think is similar or the same. I did not want the user being able to "track back" to the log in screen once they had logged in.

I built my log in view as a modal view that is called in the ViewDidLoad of the main app view controller if the user is not logged in:

if (isUserLoggedIn == NO) {
    [self performSegueWithIdentifier:@"logInUserModalSegue" sender:self];
} 

The main view loads briefly and then the LogIn modal view animates up, covering everything.

When the user hits log in, I check the credentials and then dismiss (or not) the modal controller, like this:

if (logInStatus == YES) {
    [[self presentingViewController] dismissViewControllerAnimated:YES
                                                        completion:NO];
    } else {
    self.errorDisplay.text = @"Sorry, there was an error logging in.";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文