1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
22 #include "CyteKit/TabBarController.h"
24 #include "iPhonePrivate.h"
26 @implementation UITabBarController (Cydia)
30 @implementation CyteTabBarController
32 - (void) didReceiveMemoryWarning {
33 [super didReceiveMemoryWarning];
35 // presenting a UINavigationController on 2.x does not update its transitionView
36 // it thereby will not allow its topViewController to be unloaded by memory pressure
37 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
38 UIViewController *selected([self selectedViewController]);
39 for (UINavigationController *controller in [self viewControllers])
40 if (controller != selected)
41 if (UIViewController *top = [controller topViewController])
46 - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
47 if ([self unselectedViewController])
48 [self setUnselectedViewController:nil];
50 // presenting a UINavigationController on 2.x does not update its transitionView
51 // if this view was unloaded, the tranitionView may currently be presenting nothing
52 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
53 UINavigationController *navigation((UINavigationController *) viewController);
54 [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
55 [navigation popViewControllerAnimated:NO];
59 - (void) dismissModalViewControllerAnimated:(BOOL)animated {
60 if ([self modalViewController] == nil && [self unselectedViewController] != nil)
61 [self setUnselectedViewController:nil];
63 [super dismissModalViewControllerAnimated:YES];
66 - (void) setUnselectedViewController:(UIViewController *)transient {
67 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
68 if (transient != nil) {
69 [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
70 [self setSelectedIndex:0];
74 NSMutableArray *controllers = [[[self viewControllers] mutableCopy] autorelease];
75 if (transient != nil) {
76 UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
77 [navigation setViewControllers:[NSArray arrayWithObject:transient]];
78 transient = navigation;
80 if (transient_ == nil)
81 remembered_ = [controllers objectAtIndex:0];
82 transient_ = transient;
83 [transient_ setTabBarItem:[remembered_ tabBarItem]];
84 [controllers replaceObjectAtIndex:0 withObject:transient_];
85 [self setSelectedIndex:0];
86 [self setViewControllers:controllers];
87 [self concealTabBarSelection];
88 } else if (remembered_ != nil) {
89 [remembered_ setTabBarItem:[transient_ tabBarItem]];
90 transient_ = transient;
91 [controllers replaceObjectAtIndex:0 withObject:remembered_];
93 [self setViewControllers:controllers];
94 [self revealTabBarSelection];
98 - (UIViewController *) unselectedViewController {
102 - (void) unloadData {
105 for (UINavigationController *controller in [self viewControllers])
106 [controller unloadData];
108 if (UIViewController *selected = [self selectedViewController])
109 [selected reloadData];
111 if (UIViewController *unselected = [self unselectedViewController]) {
112 [unselected unloadData];
113 [unselected reloadData];
117 #include "InterfaceOrientation.h"