【问题标题】:iPhone- How to get the main view (1st view) every time when we switching form one tab to another tabiPhone-每次从一个选项卡切换到另一个选项卡时如何获取主视图(第一个视图)
【发布时间】:2013-05-07 05:16:13
【问题描述】:
在我的 iPhone 应用程序中,我使用了 tabbarcontroller,因为我有 4 个选项卡用于四个不同的项目
在每个选项卡中,我都有不同的视图来导航其中的事务。
我的要求是,当我通过点击标签栏项目将标签上的表单切换到另一个标签时。
T*the main view (first view ) of each tab has to be appeared instead of currently working view.*
例如:
我选择选项卡 3,在那里我执行一些操作并导航到第三个选项卡中的某个第二个视图。
-
然后我看到标签 4,然后又看到标签 3.. 然后之前的工作视图视图 2 出现在标签 3 中,
- 但是当我选择标签 3 时,我需要随时呈现第一个视图(与任何其他标签相同)
怎么办..
【问题讨论】:
标签:
iphone
objective-c
uinavigationcontroller
uitabbarcontroller
【解决方案1】:
创建 UINavigationController 的子类,将情节提要中的任何导航控制器的类更改为该类,并将此代码放入该子类中:
-(void)viewDidDisappear:(BOOL)animated {
[self popToRootViewControllerAnimated:NO];
}
当你点击另一个标签时,这个方法将被调用,它会将导航堆栈重置回根视图控制器。
【解决方案2】:
将您的视图控制器或 appdelegate 设置为您的 tabbarcontroller 的委托。实现这个委托函数
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
int selectedIndex = tabBarController.selectedIndex;
NSArray *tabbarControllers = tabBarController.viewControllers;
//Then replace tabbarControllers[selectedIndex] by your new view controller(with navigation controller)
tabBarController.viewControllers = Your replaced Array;
}