返回 AppDelegate 重新创建 uitabbarcontroller
我有一个基于标签栏视图和欢迎屏幕的应用程序(导致登录或注册过程)。基本上,如果您已登录,您将直接进入标签栏视图,如果没有,您将进入欢迎屏幕,您可以在其中选择登录或注册。假设您登录或注册,我希望标签栏视图重新出现,但是,所有声明都在 AppDelegate 中。我怎样才能“返回”并调用tabbatcontroller?我的课程结构/流程是否正确?
重复一遍:
- 用户登录 ->第一个视图是选项卡栏视图
- 用户已注销 ->欢迎屏幕视图 -->登录/注册屏幕视图 -->选项卡栏视图
我正在寻找的是我需要在用户单击登录页面中的“登录”后调用的操作方法中编写什么:
-(IBAction)done:(id)sender {
?????
}
作为参考,我的 appDelegate 是:
if(user signed in)
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstTab alloc] initWithNibName:@"FirstTab" bundle:NSBundle.mainBundle];
UIViewController *viewController2 = [[SecondTab alloc] initWithNibName:@"SecondTab" bundle:NSBundle.mainBundle];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, secondNavController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
else
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SigninTabBarTemplateViewController *landingPage = [[SigninTabBarTemplateViewController alloc] initWithNibName:@"SigninTabBarTemplateViewController" bundle:nil];
self.window.rootViewController = (UIViewController *) landingPage;
[self.window makeKeyAndVisible];
}
I have an app that is based on a tab bar view with a welcome screen (that leads to either signin or sign up process). basically, if you are logged in - you go straight to the tabbar view and if not, you go to the welcome screen, where you can chose to either go to sign in or sign up. assuming that you go to either sign in or sign up, i would like the tab bar view to reappear, however, all the declarations are in the AppDelegate. how can I "go back" and call the tabbatcontroller? is the structure / flow of my classes correct at all?
so to repeat:
- user signed in -> first view is tab bar view
- user logged out -> welcome screen view --> sign in / up screen view --> tab bar view
what i am looking for is what do i need to write in this action method that is called once the user clicks on "sign in" in the sign in page:
-(IBAction)done:(id)sender {
?????
}
for reference, my appDelegate is:
if(user signed in)
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstTab alloc] initWithNibName:@"FirstTab" bundle:NSBundle.mainBundle];
UIViewController *viewController2 = [[SecondTab alloc] initWithNibName:@"SecondTab" bundle:NSBundle.mainBundle];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, secondNavController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
else
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SigninTabBarTemplateViewController *landingPage = [[SigninTabBarTemplateViewController alloc] initWithNibName:@"SigninTabBarTemplateViewController" bundle:nil];
self.window.rootViewController = (UIViewController *) landingPage;
[self.window makeKeyAndVisible];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以考虑很多选择。
使用委托可以轻松实现这一点。如果您想关闭以模态方式呈现的 VC,请为其指定一个
delegate
属性。需要时,代表将收到一条消息,让其解散 VC。使用委托的一个好方法是编写自定义协议。例如:
现在,使您想要的对象符合该协议,例如应用程序委托。
实现如下所示:
现在给
signInVC
一个委托属性,该属性将在模态呈现之前设置,并在登录过程完成时向委托发送一条消息。您可以编写任何您想要的方法,这个示例很简单,并且为委托提供一些信息很有用。例如,在这种情况下,您可以传递用户名、用户 ID 或任何您想要的内容。
另一个简单的选择是使用通知。此选项可以让任何对象在发生某事时得到通知,只要它注册即可。给定与前面示例相同的对象,应用程序委托将注册通知,而登录视图控制器将发布通知。
有关委托和通知的更多信息,请参阅与对象通信。
There are many options you can consider.
This can be easily achieved with the use of delegate. If you want to close the VC that you presented modally, give it a
delegate
property. The delegate will be sent a message when required, letting it dismiss the VC. A good way to go with delegate is to write a custom procotol.For example :
Now, make the object you want conforms to that protocol, for example the app delegate.
The implementation looks like this :
Now give
signInVC
a delegate property, which will be set before being presented modally, and send the delegate a message when the sign in process is completed.You can write any method you want, this example is simplist, and it is useful to give the delegate some informations. In this case for example you could pass a user name, or user id, or what ever you want.
Another simple option is using notifications. This option lets any object informed when something happen, as long as it register for it. Given the same objects as the previous example, the app delegate will register for the notification, while the sign in view controller will post it.
More informations about delegates and notifications in Communicating with Objects.
您可以尝试在您知道用户已成功登录的方法中执行类似的操作。(假设 SignedInTabbarViewController 是您的 TabBarController)
You could try doing something like this in the method where you know the user has successfully logged in. (Assuming SignedInTabbarViewController is your TabBarController)