[英]Resetting Tab bar controller's view controllers
In my Application I have creted view controllers for Tab Bar using XIB. 在我的应用程序中,我使用XIB创建了Tab栏的视图控制器。 I mean I added view controllers in tab bar using XIB. 我的意思是我使用XIB在选项卡栏中添加了视图控制器。 See picture, 看图片
So my application is like this. 所以我的应用程序就是这样。 I have a log out functionality that will show login page. 我有一个注销功能,它将显示登录页面。 From Login page I have displayyed tab bar as 在登录页面中,我将标签栏显示为
[self.view addSubview tabBarController.view];
When I log out I simply remove this tab bar and show login screen as 当我注销时,只需删除此标签栏,然后将登录屏幕显示为
[self.tabBarController.view removeFromSuperView];
Then It will show login screen. 然后它将显示登录屏幕。 When I login again, The view controllers inside tab bar is not reset. 当我再次登录时,选项卡栏中的视图控制器未重置。 I mean If I have showed some data like names in table view, It will be there as it is when I logged in again (some time I login as different user and I get details for previous user.). 我的意思是,如果我在表视图中显示了一些数据,例如名称,那么它将再次出现时保持原样(有时我以其他用户身份登录,并获得了先前用户的详细信息。)。 I tried 我试过了
self.tabBarController.viewControllers = nil;
to reset all view controllers, but it not works any more. 重置所有视图控制器,但不再起作用。 I think each time When I log in all view controllers should call ViewDidLoad:
, currently it is calling viewWillAppear:
. 我认为每次登录时,所有视图控制器都应调用ViewDidLoad:
当前它正在调用viewWillAppear:
ViewDidLoad:
So please let me know how could I resolve this issue 所以请让我知道如何解决这个问题
I think since you are not using a fresh object once you sign out and sign in again, it is showing you with the last stage. 我认为,既然您在退出并再次登录后就没有使用新对象,那么它将向您显示最后一个阶段。 Try initializing your controller object after you have logged in may work for you. 登录后尝试初始化控制器对象可能对您有用。
Let me know if you find any problem further. 让我知道您是否还有任何问题。
Cheers Tarun 干杯塔伦
All it's troubles because you use Interface Builder. 麻烦全都因为您使用了Interface Builder。 Ok, try to explain. 好的,尝试解释一下。 In your class like MyViewController.m ypu need set property like this: 在像MyViewController.m这样的类中,ypu需要这样的set属性:
@interface MyViewController : UIViewController
{
IBOutlet UITabBarController *mytabbar;
}
In IB (Interface Builder) you need set mytabbar
property name for your UITabBarController. 在IB(界面生成器)中,您需要为UITabBarController设置mytabbar
属性名称。 After that you can rectreate this variable, because you have pointer to this variable. 之后,您可以撤回该变量,因为您有指向该变量的指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.