在 iPhone 应用程序中刷新注销时的 tabbarcontroller 视图
我们有一个标签栏+导航控制项目。我们通过界面生成器创建了一个选项卡栏,并通过界面生成器将所有选项卡项添加到选项卡栏控制器。 我们的应用程序有一个登录屏幕,我们在开始时将其显示为模式表单。用户通过身份验证后,登录屏幕将关闭(使用dismissModalScreen)并显示主窗口。这一切工作正常。
现在,我们有一个注销选项,单击该选项我们应该显示登录屏幕。我们也能够证明这一点。但问题是,一旦用户再次通过身份验证,我们希望所有屏幕都重新加载。目前,所有屏幕都保持其状态并保留以前的数据。
我们尝试做的是:
[AppDelegate tabBarController release];
AppDelegate.tabBarController = nil;
我们尝试释放 tabBarController 并将其设置为 nil。但是,一旦显示视图,我们就无法选择任何选项卡,并且视图为空白。
我们需要的是:
用户第二次登录后,如何释放和重新加载属于选项卡栏的每个视图控制器。
我们将非常感谢您的帮助。
We have a tab bar + navigation control project. We have created a tab bar through interface builder and added all tab items to the tab bar controller through through interface builder.
Our application has a login screen which we are showing as a modal form at the beginning. Once the user is authenticated, the login screen is dismissed (using dismissModalScreen) and the MainWindow is shown. This is all working fine.
Now, we have a logout option clicking on which we should show the login screen back. We are able to show that as well. But the issue is once the user is authenticated again, we want all the screens to be loaded freshly. Currently, all screens maintain their state and retain previous data.
What we have tried to do is:
[AppDelegate tabBarController release];
AppDelegate.tabBarController = nil;
We have tried releasing the tabBarController and setting it to nil. But once the view is shown, we are not able to select any of the tabs and the view is blank.
What we need is:
Once the user logs in second time, how to release and reload each viewcontroller which are part of tabbar.
Your help will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们已经找到了出路。我们现在要做的是,一旦用户重新登录,我们就会释放视图控制器并重新创建它们并将其设置回 uitabbar。
NSMutableArray *arrControllers = [[AppDelegate.tabBarController.viewControllers] mutablecopy];
[arrControllersremoveAtIndex:3];
[arrControllersremoveAtIndex:2];
----创建新控制器
UIViewController viewController2 = [[UIViewController alloc] initWithNibName:@"viewController2" bundle:nil] autorelease];
UIViewController viewController3 = [[UIViewController alloc] initWithNibName:@"viewController3" bundle:nil] autorelease];
--创建导航控制器
UINavigationController navViewController2 = [[[UINavigationController alloc] initWithRootViewController:viewController2 ] autorelease];
UINavigationController navViewController3 = [[[UINavigationController alloc] initWithRootViewController:viewController3 ] autorelease];
[arrControllers addObject:navViewController2];
[arrControllers addObject:navViewController3];
[AppDelegate.tabViewController setViewControllers:arrControllers];
进行此更改后,它运行良好。
我们面临的唯一问题是,如果我们从数组中释放所有对象,我们会得到一个 carsh。是因为,当您释放 allObjects 时,第一个控制器(即 RootViewController)也被释放了?
谢谢
We have found a way out. What we are doing now is, once the user logs back in, we are releasing the view controllers and recreating them and setting it back to the uitabbar.
NSMutableArray *arrControllers = [[AppDelegate.tabBarController.viewControllers] mutablecopy];
[arrControllers removeAtIndex:3];
[arrControllers removeAtIndex:2];
----Create New Controllers
UIViewController viewController2 = [[UIViewController alloc] initWithNibName:@"viewController2" bundle:nil] autorelease];
UIViewController viewController3 = [[UIViewController alloc] initWithNibName:@"viewController3" bundle:nil] autorelease];
--Create Nav controller
UINavigationController navViewController2 = [[[UINavigationController alloc] initWithRootViewController:viewController2 ] autorelease];
UINavigationController navViewController3 = [[[UINavigationController alloc] initWithRootViewController:viewController3 ] autorelease];
[arrControllers addObject:navViewController2];
[arrControllers addObject:navViewController3];
[AppDelegate.tabViewController setViewControllers:arrControllers];
It is working fine after this change.
Only problem we faced was if we release all objects from the array, we get a carsh. Is it because, when you release allObjects, the first controller which is the RootViewController is getting released?
Thanks